Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Hide ActionBar, keep Tabs

Tags:

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!

like image 910
josephoneill Avatar asked Feb 20 '13 20:02

josephoneill


People also ask

How to hide ActionBar in Android Kotlin?

If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme. AppCompat.

How to hide toolbar on Android?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How to remove ActionBar Android studio?

If we want to remove the ActionBar only from specific activities, we can create a child theme with the AppTheme as it's parent, set windowActionBar to false and windowNoTitle to true and then apply this theme on an activity level by using the android:theme attribute in the AndroidManifest. xml file.


4 Answers

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

getSupportActionBar().setDisplayShowHomeEnabled(false);               getSupportActionBar().setDisplayShowTitleEnabled(false); 
like image 67
Ahmad Avatar answered Nov 30 '22 22:11

Ahmad


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; } 
like image 30
Psypher Avatar answered Nov 30 '22 22:11

Psypher


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);
like image 26
Rohit Avatar answered Nov 30 '22 23:11

Rohit


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)
like image 43
Confuse Avatar answered Nov 30 '22 22:11

Confuse