2011-04-21 27 views
4

我可以知道,下面的代碼。什麼是TabHost.newTabSpec中使用的參數標籤的用法

// Initialize a TabSpec for each tab and add it to the TabHost 
spec = tabHost.newTabSpec("artists").setIndicator("The Artists", 
        res.getDrawable(R.drawable.ic_tab_artists)) 
       .setContent(intent); 

什麼是具有「藝術家」的標籤作爲newTagSpec參數的目的是什麼?我應該使用國際化字符串如

spec = tabHost.newTabSpec(getString(R.string.artists)).setIndicator(getString(R.string.the_artists), 
        res.getDrawable(R.drawable.ic_tab_artists)) 
       .setContent(intent); 

回答

2

我這樣做,我的所有標籤,但你做到這一點,像這樣:

spec = tabHost.newTabSpec("groups").setIndicator(getString(R.string.tab_groups), res.getDrawable(R.drawable.ic_tab_groups)).setContent(intent); 

「組」是怎麼計算出R.drawable.ic_tab_NameInNewTabSpec。

+3

但是,這是否解釋了「組」標籤的用途?什麼是ic_tab_NameInNewTabSpec的方式? – 2011-04-21 02:50:49

+0

這是您在newTabSpec()中使用的名稱...這就是「組」標籤的用途。它告訴編譯器使用ic_tab_groups。 – 2011-04-21 11:21:45

+0

任何說明這就是它的文檔? – irwinb 2012-08-30 20:56:11

5

tag參數是TabHost使用的選項卡的ID。當重寫TabHost方法時,該標記可能是有用的,例如

TextView t = (TextView) findViewById(R.id.nav_bar); 

... 

tabHost.setOnTabChangedListener(new OnTabChangeListener() { 
    @Override 
    public void onTabChanged(String tabID){ 
     t.setText(tabID); 
    } 
}); 

在這個例子中,t是表示「導航欄」和tabID一個TextView的是,用戶切換到的標籤的標籤。這種簡單的重寫方法的目的是將導航欄中的文本更改爲選項卡的名稱/標記。

相關問題