问题描述
在一个 TabHost 小部件,我可以创造一个新的标签,其内容(意向)使用TabHost.addTab(TabHost.TabSpec则tabspec)。
In a TabHost widget, I can create a new tab with its content (Intent) using TabHost.addTab(TabHost.TabSpec tabSpec).
我们可以通过调用clearAllTabs(),但我无法弄清楚如何去除标签或只是更换新的意图的选项卡里面的内容(意向)。
We can remove all tabs we created by calling clearAllTabs(), but I can't figure out how to remove the tab or just replace the content (Intent) inside the tab with new Intent.
所以我需要的东西,像 removeTab(INT指数)
so what I need something like removeTab(int index)
推荐答案
其实,clearAllTabs做的是:
Actually, clearAllTabs does that :
public void clearAllTabs() {
mTabWidget.removeAllViews();
initTabHost();
mTabContent.removeAllViews();
mTabSpecs.clear();
requestLayout();
invalidate();
}
和方法removeAllViews来自类的ViewGroup
。幸运的是,的ViewGroup
确实有方法去除只有一个观点:
And the method removeAllViews comes from the class ViewGroup
. Luckily, ViewGroup
does have methods to remove only one view :
-
removeView(查看视图)
-
removeViewAt(INT指数)
-
removeViewInLayout(查看视图)
removeView(View view)
removeViewAt(int index)
removeViewInLayout(View view)
知道了,我会建议继承 TabWidget
和 TabHost
添加你需要的行为。也许还有一个更简单的方法,但是这是唯一一个我能想到的。祝你好运
Knowing that, I would recommend to subclass TabWidget
and TabHost
to add the behaviour you need. Maybe there is an easier way but that's the only one I can think of.Good luck
这篇关于如何从TabHost移除标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!