Android Tabhost Problem - .setIndicator

二次信任 提交于 2019-12-04 12:37:44

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