Android Tabhost Problem -.setIndicator

First let me clarify that I already mentioned the SO question related to "Android - TAbhost".

I did googling about "Android Tabhost" but couldn't find a solution.

My problem:

If they have <3 tabs, then this is normal. but Supporse, if we have 4 tabs with an indicator title like TabHost1, TabHost2, TabHost3, TabHost4). But this tab title is not set with a tab. therefore there is a way to fit the title text (i.e. indicator) inside the tab

+4
android android-tabhost android-widget tabwidget
source share
2 answers

I thought the source of our problem was somewhere in the framework code. And of course, I found some clues:

First, if you look inside the TabWidget code , you will see that the label set in setIndicator is passed an inner class called LabelIndicatorStrategy , which takes care of inflating the view associated with the top of the tab. This inflation is done using the xml file tab_indicator.xml . This layout is based on a RelativeLayout containing ImageView and a TextView . And if you look at the properties of textview, you will see that this refers to the style in android styles.xml . And here, finally, you understand that we have IT:

 <item name="ellipsize">marquee</item> <item name="singleLine">true</item> 

So, now, 2 options:
First, redefine the style by creating your own style, which, in my opinion, will be really painless, and then change these properties to what suits you. Although the result may not be very pleasant. this will require some testing.
Or put on gloves and copy the code from the TabWidget class, because another problem is that the inner class I mentioned is ... PRIVATE, so inheritance is not possible if I'm not mistaken ... So I think a lot more pain than styles.xml. Hope this inspires you, keep me updated on what you get, please. I'm still interested.

+4
source share

I solved the problem above by decreasing the font size, check the Style.xml code Style.xml :

 <resources> <style name="MyTheme" parent="@android:style/Theme.Light"> <item name="android:tabWidgetStyle">@style/LightTabWidget</item> </style> <style name="LightTabWidget" parent="@android:style/Widget.TabWidget"> <item name="android:textSize">12px</item> <item name="android:textColor">#1E90FF</item> </style> </resources> 
+1
source share

All Articles