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

前端 未结 4 587
囚心锁ツ
囚心锁ツ 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 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);
    }
    

提交回复
热议问题