2011-04-21 75 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的是,用户切换到的标签的标签。这种简单的重写方法的目的是将导航栏中的文本更改为选项卡的名称/标记。

相关问题