Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionbar convert tabs to list navigation if there is no room

I have an actionbar with a logo, a title, 2 tabs and a search function. On a phone (3.5") everything works fine. The actionbar has 2 lines. The logo title and the search function appear on the first line and the tabs apear on the second line. enter image description here

On my tablet (7") everyting is shown on a single line. But the tabs will be convert to a list when i click the search icon. tabs as list navigation

How can i split the (sherlock)actionbar in 2 lines on my 7" tabblet? Or is there an other way to solve this problem?

like image 589
Rickyrick Avatar asked Nov 26 '12 14:11

Rickyrick


2 Answers

In ActionBarSherlock, there is a boolean value(abs__action_bar_embed_tabs) that determine whether the Tabs should be embed in ActionBar, and this value is stored in two files.

  • In values/abs__bools.xml. It is false.
  • In values-w480/abs__bools.xml. It is true.

This means Tabs will be embed only if the width of device is bigger than 480dp.

If you want to control it all by yourself, you can just create values-w480 in your own project, and set abs__action_bar_embed_tabs to false to override the value in library project.

like image 115
faylon Avatar answered Oct 12 '22 20:10

faylon


I found a solution to separate the tabs in code.

private void embeddedTabs(Object actionBar, Boolean embed_tabs) {


try {

        if (actionBar instanceof ActionBarWrapper) {
            //ICS and forward
            try {
                Field actionBarField = actionBar.getClass().getDeclaredField("mActionBar");
                actionBarField.setAccessible(true);
                actionBar = actionBarField.get(actionBar);
            } catch (Exception e) {
                Log.e("", "Error enabling embedded tabs", e);
        }
    }
    Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class);
    setHasEmbeddedTabsMethod.setAccessible(true);
    setHasEmbeddedTabsMethod.invoke(actionBar, embed_tabs);
} catch (Exception e) {
    Log.e("", "Error marking actionbar embedded", e);
}

}

But now I have a new problem. The tabs don't fill the tabbar completely. Actionbar tabs don't fill the tabbar

like image 23
Rickyrick Avatar answered Oct 12 '22 19:10

Rickyrick