josephoneill
josephoneill

Reputation: 853

Android: Hide ActionBar, keep Tabs

To keep this simple: I have tabs in my actionbar, but the action bar take up too much space. I want that extra space. I need a way to hide the action bar, yet keep my tabs. Is there anyway to do this? Or is there a way I can get the tabs built into the action bar like it is in landscape mode? Thanks!

Upvotes: 22

Views: 10615

Answers (4)

Psypher
Psypher

Reputation: 10829

Try the below code:

    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);

Also remove the below in code which is added default when project is created:

public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
}

Upvotes: 13

Confuse
Confuse

Reputation: 5786

Ahmad's answer is correct but it requires API 11. For supporting lower APIs, use this code -

setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);

To enable it, use -

setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)

Upvotes: 1

Rohit
Rohit

Reputation: 1550

This did the trick for me

    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);

I also commented the line

    getMenuInflater().inflate(R.menu.main, menu);

Upvotes: 3

Ahmad
Ahmad

Reputation: 72533

You can have an empty Actionbar, then the tabs will occupy the space:

getSupportActionBar().setDisplayShowHomeEnabled(false);              
getSupportActionBar().setDisplayShowTitleEnabled(false);

Upvotes: 35

Related Questions