Search code examples
androidiconsandroid-tabhost

How to add icon inside a Tabbar in Android?


Currently i ma working in Android application, Using TabHost to set Five tabs, then i tried to add icon inside a tabbar, but i didn't know, how to set it? please help me

Thanks in Advance

I tried here mentioned for your reference:

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

Solution

  • Use the overloaded setIndicator() method that also accepts a Drawable parameter:

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

    Example:

    tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("5", getResources().getDrawable(android.R.drawable.arrow_down_float)).setContent(new Intent(this, Fifth.class)));