How to style ActionaBar Tab text in Android?

2019-01-25 13:23发布

问题:

I am using ActionBarShrelock to provide Action Bars for pre honeycomb devices. I have following code in my themes.xml file...

 <style name="My.Tab.Style" parent="@android:style/Widget.TabWidget">
        <item name="android:textAppearance">@style/MyCustomTabTextStyle</item>
    </style>

   <style name="MyCustomTabTextStyle" parent="Widget.Sherlock.ActionBar.TabText">
        <item name="android:textAppearance">@android:style/TextAppearance.Medium</item>
        <item name="android:textSize">14sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/tabbar_text_color</item>
    </style>

Than I use this it as

<item name="android:actionBarTabTextStyle">@style/My.Tab.Style</item>
<item name="actionBarTabTextStyle">@style/My.Tab.Style</item>

Can any one explain why I am getting some shadow on the last letters of Tab ? How can I get rid of that ? plz help.. I have tried everything but that shadow is always there..

回答1:

I solved the problem using a custom style.

  1. First I created a custom style

    <style name="My.TabText.Style" parent="@style/Widget.Sherlock.ActionBar.TabText">       
        <item name="android:textAppearance">@android:style/TextAppearance.Medium</item>
        <item name="android:textSize">16sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/tabbar_text_color</item>
        <item name="android:textAllCaps">false</item>
        <!-- <item name="android:ellipsize">none</item> --> 
        <item name="android:maxLines">1</item>
    </style>
    
  2. Than i used that style in my Theme

    <item name="actionBarTabTextStyle">@style/My.TabText.Style</item>
    <item name="android:actionBarTabTextStyle">@style/My.TabText.Style</item>
    


回答2:

As far as I know ActionBar Shelock uses the same from the normal action bar. Based on that assumption:

a previous answer I gave ActionBar text color

and a generator http://jgilfelt.github.com/android-actionbarstylegenerator/



回答3:

In folder values add

<item name="actionBarTabTextStyle">@style/My.TabText.Style</item>

In folder values-v14

<item name="android:actionBarTabTextStyle">@style/My.TabText.Style</item>