Android ActionBar: show/hide tabs dynamically?

半世苍凉 提交于 2019-12-04 02:36:39

To remove the actionbar tabs dynamically, you simply need:

getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);

To add them on the fly, simply do:

getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

For the second case, the assumption is that after setting the navigation mode, you will also add tabs, to the action bar, similar to this:

for (int resourceId : tabs) {
        actionBar.addTab(actionBar.newTab().setText(resourceId)
                .setTabListener(this));
}
Raj Sharma
public void onDrawerClosed(View view) {
    getActionBar().setTitle(mTitle);
    // calling onPrepareOptionsMenu() to show action bar icons
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    invalidateOptionsMenu();
}

public void onDrawerOpened(View drawerView) {
    getActionBar().setTitle(mDrawerTitle);
    // calling onPrepareOptionsMenu() to hide action bar icons
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    invalidateOptionsMenu();
}

This is working as intended, since the tab is being selected because it was not appearing. I suggest you to do by your own the control in TabListener.

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