2013-01-23 36 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");