Remove title in Toolbar in appcompat-v7
Asked Answered
H

18

191

The documentation of Toolbar says

If an app uses a logo image it should strongly consider omitting a title and subtitle.

What is the proper way to remove the title?

Homophonous answered 30/10, 2014 at 8:31 Comment(4)
where is the problem if you just set it to an empty string? I dont think you got to use a custom layout which just uses a icon. Guess thats overkill?Accoutre
@maffelbaffel Nothing wrong with setting an empty string but it feels improper. But yea, using a custom layout would be overkill.Homophonous
I had to do: toolbar.setTitle("");Androecium
@FerranMaylinch Yes, this is work for me too! I Use toolbar.setTitle(null); which result into Application Name as a default title. so i set toolbar.setTitle(""); which work fine.Atomicity
M
628
getSupportActionBar().setDisplayShowTitleEnabled(false);
Mcgray answered 2/11, 2014 at 0:52 Comment(8)
This answer and the answer by David_E work as from me if called right after calling setSupportActionBar(). Choosing this answer because this seems to be the official way to do this according to the official reference: Set whether an activity title/subtitle should be displayed.Fala
i'ts only for toolbar like actionbar, but not for clean toobar!Caddoan
How to remove it using style.xml ? Please help meSabrasabre
Worked for me. You have to use "appcompat_v7:v21" for this to work.Annetteannex
you have to check if the above will not produce a NullPonterException by doing: if(getSupportActionBar() !=null) getSupportActionBar().setDisplayShowTitleEnabled(false);Badinage
What about for older versions?Dibbell
@rockydgeekgod Write the above line directly; Do not put it in a variable first.Unpolitic
I would like to question the naming of this function... Display Show.... Whats the difference. Am I setting my Display - and what is this??!?! Shouldn't that then be set Toolbar and then say Show Title... And shouldn't the enabled be removed? Otherwise I would think that calling this function would always enable this?!?.... ?!§?!?!?!?!? :'(Salita
R
76

The correct way to hide/change the Toolbar Title is this:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);

This because when you call setSupportActionBar(toolbar);, then the getSupportActionBar() will be responsible of handling everything to the Action Bar, not the toolbar object.

See here

Reyesreykjavik answered 18/11, 2014 at 19:20 Comment(2)
setTitle(null) results in the app name becoming the title.. setTitle("") worked for me.Kobold
in xml I added <Toolbar app:title=" " // title is a space . WorkedBaeza
M
25

Try this...

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_landing_page); 

    .....

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_landing_page);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    .....

 }
Matronize answered 20/4, 2015 at 10:53 Comment(0)
R
21

The reason for my answer on this is because the most upvoted answer itself failed to solve my problem. I have figured out this problem by doing this.

<activity android:name="NAME OF YOUR ACTIVITY"
    android:label="" />

Hope this will help others too.

Rozina answered 14/3, 2016 at 18:32 Comment(1)
This is not a good idea. If you have an <intent-filter> on that Activity to allow users to open your app by clicking a URL (for example), the disambiguation dialog will not have any title!Emetic
I
10

Another way to remove the title from your Toolbar is to null it out like so:

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
toolbar.setTitle(null);
Interlope answered 30/10, 2014 at 15:21 Comment(0)
M
6

this

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    //toolbar.setNavigationIcon(R.drawable.ic_toolbar);
    toolbar.setTitle("");
    toolbar.setSubtitle("");
    //toolbar.setLogo(R.drawable.ic_toolbar);
Meaty answered 1/8, 2018 at 9:42 Comment(0)
O
5

If you are using Toolbar try below code:

toolbar.setTitle("");
Oaxaca answered 5/8, 2017 at 7:12 Comment(0)
G
3
 Toolbar actionBar = (Toolbar)findViewById(R.id.toolbar);
    actionBar.addView(view);
    setSupportActionBar(actionBar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

take note of this line getSupportActionBar().setDisplayShowTitleEnabled(false);

Guidebook answered 26/4, 2017 at 11:7 Comment(1)
actionBar.addView(view); is a custom view i am adding to the toolbarGuidebook
F
3

Just add this attribute to your toolbar

app:title=" "
Forepart answered 10/1, 2019 at 13:32 Comment(0)
M
2

You can use any one of bellow as both works same way: getSupportActionBar().setDisplayShowTitleEnabled(false); and getSupportActionBar().setTitle(null);

Where to use:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);

Or :

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    getSupportActionBar().setTitle(null);
Maegan answered 2/3, 2017 at 13:25 Comment(0)
C
1

The correct way to hide title/label of ToolBar the following codes:

  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(null);
Chicoine answered 7/6, 2016 at 11:28 Comment(0)
G
1

I dont know whether this is the correct way or not but I have changed my style like this.

<style name="NoActionBarStyle" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
</style>
Group answered 22/5, 2017 at 7:33 Comment(0)
F
1
Toolbar toolbar = findViewById(R.id.myToolbar);
    toolbar.setTitle("");
Fraternity answered 17/1, 2019 at 17:0 Comment(0)
P
1

if your using default toolbar then you can add this line of code

Objects.requireNonNull(getSupportActionBar()).setDisplayShowTitleEnabled(false);
Physics answered 23/1, 2019 at 7:0 Comment(0)
B
0

Nobody mentioned:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
    }
Brahmin answered 4/8, 2016 at 20:15 Comment(1)
Read the question carefully before answering, OP has asked to remove title from toolbarAcatalectic
C
0

toolbar.setTitle(null);// remove the title

Cinelli answered 4/1, 2018 at 4:36 Comment(0)
J
0

It's obvious, but the App Theme selection in design is just for display a draft during layout edition, is not related to real app looking in cell phone. In my case, there is no title bar in design but the title bar was always in cell phone.

I'm starting with Android programming and fight to discover a right solution.

Just change the manifest file (AndroidManifest.xml) is not enough because the style need to be predefined is styles.xml. Also is useless change the layout files.

All proposed solution in Java or Kotlin has failed for me. Some of them crash the app. And if one never (like me) intend to use the title bar in app, the static solution is cleaner.

For me the only solution that works in 2019 (Android Studio 3.4.1) is:

in styles.xml (under app/res/values) add the lines:

   <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

After in AndroidManifest.xml (under app/manifests)

Replace

android:theme="@style/AppTheme">

by

android:theme="@style/AppTheme.NoActionBar">
Jessamyn answered 7/6, 2019 at 13:54 Comment(5)
The question asked was to remove the toolbar title, Not the toolbar itself.Gooseherd
I didn't understand it that way, because it makes no sense to leave an empty bar, but I think you must be right.Jessamyn
Yes, Sometimes we have action icons on a toolbar. For example "a search icon". So we need the toolbar in that case but we don't want the title.Gooseherd
I've got it. However, this tip it can be useful for someone. At start, I have some problems with it.Jessamyn
Sometimes I browse a question in StackOverflow and find some collateral benefit in some answer.Jessamyn
V
0

Just adding an empty string in the label of <application> (not <activity>) in AndroidMenifest.xmllike that -

<application
            android:label=""
            android:theme="@style/AppTheme">
            <activity
             .
             .
             .
             .
            </activity>
    </application>
Vickeyvicki answered 23/11, 2020 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.