在tabhost设置文本 - Android

时间:2013-01-23 09:12:08

标签: android android-tabhost

如何自动更改 tabhost 标签的名称?

TabHost tmp = (TabHost) findViewById(R.id.tabhost);
tmp.getTabWidget().getChildAt(0).findViewById(android.R.id.title).setText("Test");
文本视图未定义

SetText(string),为什么?

由于

2 个答案:

答案 0 :(得分:1)

要更改标签文本,您需要获取视图 TextView,它被设置为标签的标题,您可以这样更改:

TabHost tabhost = getTabHost();
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) 
{
    TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
    tv.setText(.....);
} 

有关TabHost的更多信息,请参阅此链接 http://developer.android.com/reference/android/widget/TabHost.html

答案 1 :(得分:0)

LinearLayout rLayout = (LinearLayout) tmp.getTabWidget().getChildAt(Pos_of_ur_tab_in_tab_widget_for_which_text_to_changed);
((TextView)rLayout.getChildAt(position_of_ur_textview_child_in_tab_layout)).setText("your_text");