2013-01-23 35 views
0

如何自动更改tabhost选项卡的名称?在tabhost设置文本 - Android

TabHost tmp = (TabHost) findViewById(R.id.tabhost); 
tmp.getTabWidget().getChildAt(0).findViewById(android.R.id.title).setText("Test"); 

SetText(string)未定义为文本视图,为什么?

感谢

回答

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

+0

请告诉我一下如果我们需要两个textviews作为TI标签?像http://imgur.com/9ekZ4qc –

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