2012-08-29 28 views
3

目前我可以在Android應用程序工作,使用TabHost設置五個選項卡,然後我試圖在標籤欄內添加圖標,但我不知道,如何設置它?請幫我如何在Android中的Tabbar中添加圖標?

由於提前

我試圖在這裏,供大家參考提到:

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

回答

3

使用也接受一個可繪製參數重載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))); 
+1

感謝您的回覆,現在我確認它儘快回覆您。 – SampathKumar

+1

非常感謝,它的工作很好。 – SampathKumar

相關問題