选择选项卡时更改选项卡文本颜色

时间:2016-06-13 08:45:11

标签: android

我有Tab文本是蓝色,背景是白色。我想在选中标签时显示蓝色背景和白色标签文字。

我使用选择器更改了背景。但我尝试了多次文本颜色选择时没有改变。请帮帮我。

styles.xml

<style name="MainTheme" parent="android:Theme.Holo.Light.DarkActionBar">   
    <item name="android:actionBarTabTextStyle">@style/tab_text_color</item>
</style>

<style name="actionbar_tab_style" parent="@android:style/Widget.Holo.Light.ActionBar.TabBar">
     <item name="android:background">@drawable/tab_background_select</item>
    <item name="android:textColor">@drawable/tab_text_select</item> 
</style>

tab_background_select.xml

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_selected="true"
        android:drawable="@color/blue"/>
</selector>

tab_text_select.xml

<?xml version="1.0" encoding="utf-8"?> 

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
   <item 
        android:state_selected="true"
        android:color="#FFFFFF"/>
    <item 
        android:state_selected="false"
        android:color="#0000FF"/>
      <!--   
        <item android:state_selected="true">
            <shape>
                <solid android:color="@color/white"/>
            </shape>
        </item>
        <item>
            <shape>
                <solid android:color="@color/light_blue"/>
            </shape>
        </item> -->

</selector>

1 个答案:

答案 0 :(得分:0)

我找到了答案。我必须将tab_text_select.xml放在ti res / colors文件夹中(如果你没有文件夹只是创建它)。

然后

<style name="actionbar_tab_text_style" parent="@android:style/Widget.Holo.Light.ActionBar.TabText">
 <item name="android:textColor">@color/tab_background_select</item>

然后将上述样式应用于主题名称android:actionBarTabTextStyle