Remove title in Toolbar in appcompat-v7

145,194

Solution 1

getSupportActionBar().setDisplayShowTitleEnabled(false);

Solution 2

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

Solution 3

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);

    .....

 }

Solution 4

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.

Solution 5

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);
Share:
145,194

Related videos on Youtube

timemanx
Author by

timemanx

Updated on November 24, 2020

Comments

  • timemanx
    timemanx over 3 years

    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?

    • Wagner Michael
      Wagner Michael over 9 years
      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?
    • timemanx
      timemanx over 9 years
      @maffelbaffel Nothing wrong with setting an empty string but it feels improper. But yea, using a custom layout would be overkill.
    • Ferran Maylinch
      Ferran Maylinch over 8 years
      I had to do: toolbar.setTitle("");
    • ULHAS PATIL
      ULHAS PATIL over 8 years
      @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.
  • user1354603
    user1354603 about 9 years
    setTitle(null) results in the app name becoming the title.. setTitle("") worked for me.
  • C0D3LIC1OU5
    C0D3LIC1OU5 almost 9 years
    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.
  • iscariot
    iscariot almost 9 years
    i'ts only for toolbar like actionbar, but not for clean toobar!
  • Anand Savjani
    Anand Savjani almost 9 years
    How to remove it using style.xml ? Please help me
  • V_J
    V_J almost 9 years
    Worked for me. You have to use "appcompat_v7:v21" for this to work.
  • Albert Vila Calvo
    Albert Vila Calvo almost 8 years
    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!
  • iOSAndroidWindowsMobileAppsDev
    iOSAndroidWindowsMobileAppsDev over 7 years
    you have to check if the above will not produce a NullPonterException by doing: if(getSupportActionBar() !=null) getSupportActionBar().setDisplayShowTitleEnabled(false);
  • tccpg288
    tccpg288 over 7 years
    What about for older versions?
  • suulisin
    suulisin about 7 years
    actionBar.addView(view); is a custom view i am adding to the toolbar
  • Bhavik Mehta
    Bhavik Mehta over 6 years
    Read the question carefully before answering, OP has asked to remove title from toolbar
  • Dr.jacky
    Dr.jacky over 6 years
    @rockydgeekgod Write the above line directly; Do not put it in a variable first.
  • ZooMagic
    ZooMagic about 6 years
    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?!?.... ?!§?!?!?!?!? :'(
  • Dan Alboteanu
    Dan Alboteanu over 5 years
    in xml I added <Toolbar app:title=" " // title is a space . Worked
  • RatneZ
    RatneZ over 3 years
    The question asked was to remove the toolbar title, Not the toolbar itself.
  • Paulo Buchsbaum
    Paulo Buchsbaum over 3 years
    I didn't understand it that way, because it makes no sense to leave an empty bar, but I think you must be right.
  • RatneZ
    RatneZ over 3 years
    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.
  • Paulo Buchsbaum
    Paulo Buchsbaum over 3 years
    I've got it. However, this tip it can be useful for someone. At start, I have some problems with it.
  • Paulo Buchsbaum
    Paulo Buchsbaum over 3 years
    Sometimes I browse a question in StackOverflow and find some collateral benefit in some answer.