Actionbar convert tabs to list navigation if there is no room

时光毁灭记忆、已成空白 提交于 2019-12-03 13:30:44

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.

Rickyrick

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

this method works fine for me:

JUST PUT THE NAVIGATION METHOD, AFTER ADDING ADDING TABS:

... // adding tabs

bar.setNavigationMode(ActionBar.Navigation_mode_tabs);

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