Remove title text from action bar in one action

I added an action bar with a drop-down menu to my activity, but also shows the name of the application.

Each of my actions has an action bar, and each of them uses the @android:style/Theme.Holo.Light . One of my activity screens I would like to display an action bar with a drop down menu, but I would like to hide the application title.

I saw this solution on another SO post, but I needed to change the global theme settings, and if I understood correctly, this approach would remove the name from all my action panels.

How can i do this?


Here is a screenshot:

enter image description here

+3
android
source share
4 answers

For such simple material, you just need to consult the source to find the answer: here is the full explanation: http://developer.android.com/guide/topics/ui/actionbar.html#Dropdown

and here is some manual code to enable the counter in the action bar:

  ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); 

after that, just place the listener for changes and install the counter adapter.

and you can use:

  setTitle(""); 

to remove the title. I checked my codes here, you can also try:

  requestWindowFeature(Window.FEATURE_NO_TITLE); 

It should just remove the title and leave the title bar. Remember you must call it before setContentView

happy coding.

+6
source share

Can be done with a nice one liner

 getActionBar().setDisplayShowTitleEnabled(false) 

this will hide only the title. If you also want to hide the home logo

 getActionBar().setDisplayShowHomeEnabled(false); 

When using the AppCompat support library, you must replace getActionBar() with getSupportActionBar() . It is also suggested to check if the ActionBar is null before changing the values ​​on it.

 ActionBar actionBar = getSupportActionBar() if (actionBar != null) { actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowHomeEnabled(false); } 
+13
source share

The above proposed solutions still show the name for a short time before making it invisible. I use the following, which in my opinion is the best way to achieve this:

Just disable app_name in the activity declaration in the manifest. Thus, it will never show activity in which you do not want it to be displayed:

 <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> 
0
source share

use this in your menifeast activity tag

 android:theme="@android:style/Theme.NoTitleBar" 
-4
source share

All Articles