Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
598 views
in Technique[技术] by (71.8m points)

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

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:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...