views:

264

answers:

2

Hello,

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  A: 

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.

Sephy
@Sephy gr8 answer...let me try and sure reply you about whatever happens
PM - Paresh Mayani
So paresh, did that work?
Sephy
A: 

Hello sephy, 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>
PM - Paresh Mayani
You can also try to move the characters together by using the android:textScaleX tag.
Octavian Damiean
@Octavian Damiean i didnt get what you are talking about? so pls can you ellaborate your comment with more specific detail
PM - Paresh Mayani
@Paresh Mayani: Yes sorry if it was confusing. I meant that you can also kind of "compress" the text in the tab by using textScaleX which will result in a more "compact" text. That way you can sometimes use the same text size for every TabIndicator text even tho one text might be longer and wouldn't fit. I guess to see what I mean you gotta try it.
Octavian Damiean
@Octavian Damiean oh my god, this is the simple way instead of doing the style modification, thanx for letting me know, really a simple step
PM - Paresh Mayani