Action Bar remove title and reclaim space

2019-06-24 07:37发布

问题:

I am trying to remove the title from my action bar and reclaim the space it would otherwise consume for the use of menu items.

I have tried using a custom theme but so far nothing has worked. I have tried changing the text size to 0sp, changing the color to transparent, and setting visibility to gone.

I have also tried this :

ActionBar actionbar = getActionBar();
actionbar.setDisplayShowTitleEnabled(false);

I am targeting sdk 15+ and using the standard Android action bar (i.e. not Sherlock).

Thanks for any suggestions.

Here's what I'm talking about (the area bordered in red I want back):

回答1:

Did you check out the ActionBar documentation yet? There's a method, setDisplayShowTitleEnabled(boolean) that does what you need.

Simply get a reference to your ActionBar, and call that with false:

ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);