3

目前我在Android应用程序中工作,使用TabHost设置五个标签,然后我尝试在标签栏中添加图标,但我不知道,如何设置它?请帮我

提前致谢

我试过这里提到供您参考:

//firstTab.setIcon(R.drawable.help);            
//firstTab.setIconSelected(R.drawable.help_selected);

TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("1").setContent(new Intent(this, First.class)));

tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("2").setContent(new Intent(this, Second.class)));

tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("3").setContent(new Intent(this, Third.class)));   

tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator("4").setContent(new Intent(this, Fourth.class)));

tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("5").setContent(new Intent(this, Fifth.class)));

tabHost.setCurrentTab(2);
4

1 回答 1

3

使用也接受 Drawable 参数的重载 setIndicator() 方法:

tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("5", YOUR_DRAWABLE).setContent(new Intent(this, Fifth.class)));

例子:

tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("5", getResources().getDrawable(android.R.drawable.arrow_down_float)).setContent(new Intent(this, Fifth.class)));
于 2012-08-29T06:07:31.923 回答