Reputation: 44988
I added an action bar with a dropdown menu to my activity but it also shows the application name.
Each of my activities has an action bar and each of them use the theme @android:style/Theme.Holo.Light
. One one my activity screens I would like to display the action bar with the dropdown/spinner menu but I would like to hide the application title.
I saw this solution on another SO post but it required me changing the global theme settings and if I've understood correctly, that approach would remove the title from all my action bars.
How can I do this?
Here's a screenshot:
Upvotes: 3
Views: 14816
Reputation: 6286
Can be done with a nice one liner
getActionBar().setDisplayShowTitleEnabled(false)
this will hide just the title. If you also want to hide the home logo
getActionBar().setDisplayShowHomeEnabled(false);
When using the AppCompat Support library, you should replace getActionBar()
with getSupportActionBar()
. It is also suggested that you check if the ActionBar is null before changing values on it.
ActionBar actionBar = getSupportActionBar()
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
}
Upvotes: 12
Reputation: 5053
The above proposed solutions still show the title for a brief moment before making it invisible. I use the following which I believe is the best way to achieve this:
Simple disable app_name in the activity declaration in the Manifest. This way it will never show for the activity where you don't want it to appear:
<activity
android:name="com.myapp.MainActivity"
android:label="@string/app_name" > <!-- Delete this -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Upvotes: 1
Reputation: 39836
For this kind of simple stuff you just have to go to the source to find the answer: here the full explanation: http://developer.android.com/guide/topics/ui/actionbar.html#Dropdown
and here some guide code, to include the spinner on the action bar:
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
after that is just put a listener for the changes and setting the a spinner adapter.
and you can use:
setTitle("");
to remove the title. I've been checking on my codes here, you can also give a try on:
requestWindowFeature(Window.FEATURE_NO_TITLE);
It should just remove the title, and leave the title bar. Remember that you must call this before setContentView
happy coding.
Upvotes: 6
Reputation: 10856
use this in your activity tag of menifeast
android:theme="@android:style/Theme.NoTitleBar"
Upvotes: -4