Reputation: 853
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
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
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
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
Reputation: 72533
You can have an empty Actionbar, then the tabs will occupy the space:
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
Upvotes: 35