本文介绍了Android的动作条:显示/隐藏标签动态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

是否可以删除/恢复,从动态的操作栏上的标签栏?

Is it possible to remove/restore the tab bar from the action bar dynamically?

到现在为止我通过改变操作栏的导航模式这样做。我用下面的code删除和恢复标签栏:

Up to now I did this by changing the navigation mode of the action bar. I used following code to remove and restore the tab bar:

@Override
public void restoreTabs() {
    getSupportActionBar()
    .setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    this.supportInvalidateOptionsMenu();
}

@Override
public void removeTabs() {
    getSupportActionBar()
    .setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    this.supportInvalidateOptionsMenu();
}

这是工作,但有一个很大的问题:每次我打电话 setNavigationMode onTabSelected 是所谓的 TabListener 和当前运行结束标签被重新建立。

That works, but there is a big problem: Everytime I call setNavigationMode, onTabSelected is called in the TabListener and the currently opend tab gets recreated.

推荐答案

要动态删除动作条的标签,只需要:

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));
}

这篇关于Android的动作条:显示/隐藏标签动态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:04