Remove the title text from the action bar in one single activity

前端 未结 4 574
囚心锁ツ
囚心锁ツ 2020-12-18 12:14

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 th

相关标签:
4条回答
  • 2020-12-18 12:39

    use this in your activity tag of menifeast

    android:theme="@android:style/Theme.NoTitleBar"
    
    0 讨论(0)
  • 2020-12-18 13:04

    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.

    0 讨论(0)
  • 2020-12-18 13:04

    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>
    
    0 讨论(0)
  • 2020-12-18 13:06

    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);
    }
    
    0 讨论(0)
提交回复
热议问题