Question

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.

Était-ce utile?

La solution

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.

Autres conseils

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);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top