动态地修改标签指示的机器人 [英] Modify tab indicator dynamically in Android
问题描述
我的应用程序需要动态更新选项卡指示器,我想通过调用TabSpec.setIndicator()要做到这一点,但它不工作。这是我的code:
在TabActivity的onCreate方法:
tabHost = getTabHost();
则tabspec则tabspec = tabHost.newTabSpec(ABC);
tabSpec.setIndicator(helloabc);
tabSpec.setContent(新MyViewFactory());
tabHost.addTab(则tabspec);
现在我需要改变标签指示到另一个字符串,例如,XYZ
则tabspec则tabspec = MyTabActivity.getTabSpec();
tabSpec.setIndicator(XYZ);
不过,这是行不通的。所以我想知道如何后它被添加到tabhost改变标签的指标?非常感谢。
解决方案
由于@CommonsWare,我让它用TabWidget.getChildAt,这里是我的code为了您的方便:
TextView的标题=(TextView中)tabHost.getTabWidget()。getChildAt(tabId).findViewById(android.R.id.title)
title.setText(XYZ);
我为我刚才的不正确的答案,现在删除道歉。
尝试使用<一个href="http://developer.android.com/reference/android/widget/TabWidget.html#getChildTabViewAt%28int%29"><$c$c>getChildViewAt()$c$c>在 TabWidget
。
My application needs to update tab indicator dynamically, I'm trying to do this by invoke TabSpec.setIndicator(), but it doesn't work. Here is my code:
In onCreate method of TabActivity:
tabHost = getTabHost();
TabSpec tabSpec = tabHost.newTabSpec("abc");
tabSpec.setIndicator("helloabc");
tabSpec.setContent(new MyViewFactory());
tabHost.addTab(tabSpec);
Now I need to change tab indicator to another string, for example, "xyz"
TabSpec tabSpec = MyTabActivity.getTabSpec();
tabSpec.setIndicator("xyz");
But it doesn't work. So I'd like to know how to change tab indicator after it is added to the tabhost? Many thanks.
Solution
Thanks to @CommonsWare, I make it by using TabWidget.getChildAt, here is my code for your convenience:
TextView title = (TextView) tabHost.getTabWidget().getChildAt(tabId).findViewById(android.R.id.title)
title.setText("xyz");
I apologize for my earlier incorrect answer, now deleted.
Try using getChildViewAt()
on TabWidget
.
这篇关于动态地修改标签指示的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!