如何更改标签动态称号 [英] How to change the title of the Tab Dynamically
问题描述
我有三个选项卡,在我的应用程序。下一个选项卡的事件,我想换一个其他现有选项卡的标题。这是我们提供,同时增加了标签到TabHost称号。
I have three tabs in my Application. On an event under one Tab, i want to change the title of an another existing Tab. This is the title that we provide while adding the tabs to the TabHost.
例如:。TabHost.addTab(tabHost.newTabSpec(TAB2))setIndicator(我需要动态改变)setContent ....
Eg: TabHost.addTab(tabHost.newTabSpec("Tab2")).setIndicator("I need to be Changed dynamically").setContent....
在上面的例子中,我setIndicator()下提供的TAB2的标题,应动态地改变。
In the above example, the title of the tab2 that i provided under setIndicator(), should be changed dynamically.
有没有办法做到这一点。
Is there any way to accomplish this.
推荐答案
除非你能找到一个更清洁的方法,您可以访问tabwidget本身。 包含在tabwidget是每个标签页,每个包含的ImageView和一个TextView相对布局。要直接访问TextView的选项卡中的索引为0,你可以这样做:
Unless you can find a cleaner method, you can access the tabwidget itself. Contained in the tabwidget are relative layouts for each of your tabs which each contain an imageview and a textview. To directly access the textview in the tab at index 0 you can do this:
mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)
然后就转换为一个TextView,你可以修改它不过你想要的。以下为我工作: ((TextView)mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)).setText("New");
Then just cast as a textview and you can edit it however you want. The below worked for me: ((TextView)mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)).setText("New");
这篇关于如何更改标签动态称号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!