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?

timemanx
  • 4,493
  • 6
  • 34
  • 43
  • 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? – Wagner Michael Oct 30 '14 at 08:48
  • 3
    @maffelbaffel Nothing wrong with setting an empty string but it feels improper. But yea, using a custom layout would be overkill. – timemanx Oct 30 '14 at 08:58
  • 1
    I had to do: `toolbar.setTitle("");` – Ferran Maylinch Oct 08 '15 at 10:31
  • 1
    @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. – ULHAS PATIL Nov 27 '15 at 10:19

18 Answers18

625
getSupportActionBar().setDisplayShowTitleEnabled(false);
massaimara98
  • 7,401
  • 1
  • 18
  • 18
  • 4
    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.` – C0D3LIC1OU5 Jun 01 '15 at 22:13
  • i'ts only for toolbar like actionbar, but not for clean toobar! – iscariot Jun 29 '15 at 10:03
  • 2
    How to remove it using style.xml ? Please help me – Anand Savjani Jul 16 '15 at 13:24
  • Worked for me. You have to use "appcompat_v7:v21" for this to work. – V_J Aug 14 '15 at 08:10
  • you have to check if the above will not produce a NullPonterException by doing: if(getSupportActionBar() !=null) getSupportActionBar().setDisplayShowTitleEnabled(false); – iOSAndroidWindowsMobileAppsDev Sep 07 '16 at 12:21
  • What about for older versions? – tccpg288 Sep 17 '16 at 22:46
  • @rockydgeekgod Write the above line directly; Do not put it in a variable first. – Dr.jacky Nov 07 '17 at 07:09
  • 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?!?.... ?!§?!?!?!?!? :'( – ZooMagic Mar 01 '18 at 10:16
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

David_E
  • 7,130
  • 4
  • 26
  • 29
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);

    .....

 }
Erik Ghonyan
  • 427
  • 4
  • 12
Silambarasan Poonguti
  • 9,386
  • 4
  • 45
  • 38
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.

Chandra Sekhar
  • 18,914
  • 16
  • 84
  • 125
  • 3
    This is not a good idea. If you have an `` on that Activity to allow users to open your app by clicking a URL (for example), the disambiguation dialog will not have any title! – Albert Vila Calvo Jun 06 '16 at 09:04
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);
MrEngineer13
  • 38,642
  • 13
  • 74
  • 93
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);
younes
  • 742
  • 7
  • 8
5

If you are using Toolbar try below code:

toolbar.setTitle("");
varotariya vajsi
  • 3,965
  • 37
  • 39
3
 Toolbar actionBar = (Toolbar)findViewById(R.id.toolbar);
    actionBar.addView(view);
    setSupportActionBar(actionBar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

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

suulisin
  • 1,414
  • 1
  • 10
  • 17
3

Just add this attribute to your toolbar

app:title=" "
Dyno Cris
  • 1,823
  • 1
  • 11
  • 20
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);
Crime_Master_GoGo
  • 1,641
  • 1
  • 20
  • 30
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);
Hai Rom
  • 1,751
  • 16
  • 9
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>
Idan
  • 5,405
  • 7
  • 35
  • 52
Goudam m
  • 11
  • 1
1
Toolbar toolbar = findViewById(R.id.myToolbar);
    toolbar.setTitle("");
Bacar Pereira
  • 1,025
  • 13
  • 18
1

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

Objects.requireNonNull(getSupportActionBar()).setDisplayShowTitleEnabled(false);
Jitesh Prajapati
  • 2,533
  • 4
  • 29
  • 51
0

Nobody mentioned:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
    }
Andoctorey
  • 728
  • 9
  • 11
0

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

user2167877
  • 1,676
  • 1
  • 14
  • 15
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">
Paulo Buchsbaum
  • 2,471
  • 26
  • 29
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>
Gk Mohammad Emon
  • 6,084
  • 3
  • 42
  • 42