Android Tabhost Problem - .setIndicator

十年热恋 提交于 2019-12-06 05:56:01

问题


First let me clarify that i have already referred the SO question related to "Android - 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 ??


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/3446722/android-tabhost-problem-setindicator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!