Actionbar convert tabs to list navigation if there is no room

给你一囗甜甜゛ 提交于 2020-01-12 07:37:08

问题


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.

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.

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


回答1:


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.




回答2:


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




回答3:


this method works fine for me:

JUST PUT THE NAVIGATION METHOD, AFTER ADDING ADDING TABS:

... // adding tabs

bar.setNavigationMode(ActionBar.Navigation_mode_tabs);



来源:https://stackoverflow.com/questions/13566493/actionbar-convert-tabs-to-list-navigation-if-there-is-no-room

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!