3

I'm using Theme.Holo as my parent theme for an application. However, the tabs in the tab host don't display icons. In order to display icons, I can change the theme to Theme.Light or just Theme, but then I won't have the action bar that comes with Theme.Holo.

Could someone please tell me how I could display icons on the tab host when using Theme.Holo? I'm referring to the iOS-like tab bar icons.

Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
Sorin Cioban
  • 2,237
  • 6
  • 30
  • 36

2 Answers2

3

Dont know if this solves your problem, but if you remove the text, the icon will be displayed.

This is the code I use:

TabHost tabHost = getTabHost();
Intent intent = new Intent().setClass(this, Overview.class);

spec = tabHost.newTabSpec("overview")
           .setIndicator(Build.VERSION.SDK_INT < 11 ? this.getString(R.string.descr) : "", res.getDrawable(R.drawable.tab_overview))
           .setContent(intent);
Philipp E.
  • 3,296
  • 3
  • 34
  • 52
2

It seems like iconed tabs are not used anymore.

You can use a great library I use for tabs (ViewPagerExtentions) which lets you swipe between tabs, and to set icon for every tab, like below: enter image description here

You need to download the library. In the example project the layout you want is: activity_fixed_icon_tabs.xml. It is quite straight forward but if you need any help you can ask me.

If you don't want to get your hands dirty, there is a solution for your problem, provided Here. Basically you can get to the ImageView inside the tab and call img.setVisibillity(View.VISIBLE).

Then he says that in android<3.0 it messes up the tab, but he provides a solution for this also. You can check which android version the device runs, and then do accordingly. But as I understand, it won't be a problem for you because you want to use the ActionBar always.

I recommend you to use the ViewPagerExtentions library because it also adds swipe functionallity which is very fancy. But even if you don't want to use this, you have a solution.

Community
  • 1
  • 1
RE6
  • 2,684
  • 4
  • 31
  • 57
  • Interesting. However, I'd much appreciate a way to do this using the built-in tab host... A +1, and I'll give you the bounty if no other answers appear. – Richard J. Ross III Oct 10 '12 at 15:08
  • Great libraries are always welcome. @RichardJ.RossIII I have an app which utilizes the TabHost and working on all versions AFAIK. If no one answers I will prepare a small tutorial. – Sherif elKhatib Oct 10 '12 at 15:10
  • @RichardJ.RossIII I did give you a solution to use with the `TabHost`. Here the post again: http://stackoverflow.com/questions/10747507/why-are-the-images-in-widgettab-not-shown-if-minsdkversion10 Look at the update in the end of his message – RE6 Oct 10 '12 at 15:23