Pages

Sunday, September 27, 2015

Hide ActionBar Title

So I'm new to Android development, and was playing around with a sample application template. Using the ActionBar to place tabbed navigation up top, but I want to hide the title. Using the FEATURE_NO_TITLE method crashes (and yes it was before setContentView). Tried many different android:theme settings in the manifest. Nothing worked.

Then I stumbled upon this, which did work:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(0); // <----- THIS IS THE PART THAT WORKED.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // etc...
}
Also worth noting that in my case I'm not displaying an options menu, via:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    return false;
}

No comments:

Post a Comment