Android Tabhost Problem - .setIndicator
First let me clarify that i have already referred the SO question related to "Android开发者_如何学Go - TAbhost".
I have done googling about "Android Tabhost" but failed to find the solution.
My problem is:
If are having <3 tabs then it is fine. but Supporse if we are having 4 tabs with indicator title as TabHost1, TabHost2, TabHost3, TabHost4). But this title in Tab does not get fitted with tab. so is there any way to fit the Title Text (i.e. indicator) inside the tab ??
I thought the source of our issue was somewhere in the framework's code. And sure enough, I found some clues :
First, if you look inside the TabWidget
code, you will see that the label you set in setIndicator
is passed to an inner class called LabelIndicatorStrategy
which will take care of inflating the view associated to the top part of the tab. This inflation is done using an xml file tab_indicator.xml. This layout is based on a RelativeLayout
containing an ImageView
and a TextView
. And if you look at the properties of the textview, you will see that it refers to a style in android styles.xml. And here finally, you realize that we have THAT :
<item name="ellipsize">marquee</item>
<item name="singleLine">true</item>
So, now, 2 options :
First, override the style by creating your own style, which in my opinion would be the really painless way and then change these properties to something that suits you better. Though the result might not be very nice. this will require some testing.
Or, put on your gloves and copy the code from the TabWidget class, because another issue here is that the inner class I mentionned is... PRIVATE so, no inheritance possible if I'm not mistaken... SO I think, much much more pain than the styles.xml's way.
Hope this will inspire you, keep me posted of what you get please. I'm still interested.
i have solved the above issue by decreasing the size of Font, check the below code of 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>
精彩评论