Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only display tabs in action bar

I've just used ActionBar Sherlock to implement the android action bar on pre 3.0 android devices. I'm having one issue when I'm using tab navigation though.

Currently the action bar is devided in two rows at the top of the screen. The first row contains the app icon and app title, while the second row contains my navigation tabs. I tried to remove the top bar with actionBar.setDisplayOptions(0);, but now i still have two rows, but the top row is empty. How can I remove this top row?

Thanks!

like image 719
Robin Heggelund Hansen Avatar asked Mar 05 '12 10:03

Robin Heggelund Hansen


People also ask

How do I customize my action bar?

This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I replace my action bar toolbar?

To replace an app's default action bar with a Toolbar : Create a new custom theme and modify the app's properties so that it uses this new theme. Disable the windowActionBar attribute in the custom theme and enable the windowNoTitle attribute. Define a layout for the Toolbar .

What is action toolbar?

An on-screen toolbar displaying icons that are clicked or tapped to perform various functions. For example, the menu bar at the top of an Android app is called an action bar.


2 Answers

I recognize this was posted about a month ago, but I think I can lend a hand. Try running these three methods just after constructing your action bar:

    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayShowTitleEnabled(false);
    bar.setDisplayShowHomeEnabled(false);

The first just sets the AB to tabs, which I assume you've already done. The second disables the String title up top (I should note that it appears when the app first launches, but then disappears very quickly), and the third shuts off the icon with the same functionality as the previous method. I actually had the same thing you're dealing with occur in my app, but once I ran both of those methods, the extra, and blank, top-most bar disappeared.

like image 71
Davek804 Avatar answered Sep 21 '22 18:09

Davek804


In addition to the accepted answer, Just remove onCreateOptionsMenu and onOptionsItemSelected to get clean tab view without having any empty action bar.

like image 31
Saad Mahmud Avatar answered Sep 21 '22 18:09

Saad Mahmud