无法设置操作栏选项卡的自定义文本颜色

时间:2014-07-21 19:16:01

标签: android xml android-actionbar customization

我正在使用android studio V0.82 我试图在按下时修改选项卡的文本颜色,但它不会像预期的那样发生。 下面是我的style.xml和drawable / tabtextcolor代码。 如果有人能告诉我这里有什么问题。

style.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <!-- <item name="android:windowBackground">@null</item> -->
    <item name="actionBarStyle">@style/ActionBarStyle.Transparent</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="actionBarDivider">@color/black</item>

    <item name="actionBarTabBarStyle">@color/black</item>

</style>

<style name="ActionBarStyle.Transparent" parent="@android:Widget.ActionBar">
    <item name="background">@null</item>
    <item name="titleTextStyle">@style/ActionBarStyle.Transparent.TitleTextStyle</item>
    <item name="actionBarTabTextStyle">@style/MyTabTextStyle</item>

</style>

<style name="ActionBarStyle.Transparent.TitleTextStyle" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:textColor">@color/white</item>
</style>

<style name="MyTabTextStyle" parent="@android:Widget.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/tabcolor</item>
</style>>

抽拉/ tabtextstyle.xml

<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
<item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@color/tabcolor" />

<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@color/white" />
<item android:state_focused="true" android:state_selected="true"  android:state_pressed="false" android:drawable="@color/tabcolor" />

<!-- Pressed -->
<!--    Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@color/tabcolor" />
<item android:state_focused="false" android:state_selected="true"  android:state_pressed="true" android:drawable="@color/tabcolor" />

1 个答案:

答案 0 :(得分:0)

<style name="TabTextStyle"
    parent="@style/Widget.AppCompat.ActionBar.TabText">
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">10dp</item>
</style>

将它放在常规值文件夹中的styles.xml中 并把这个

<item name="actionBarTabTextStyle">@style/TabTextStyle</item>

在你的两个样式xml文件中都是这样的

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!-- <item name="android:windowBackground">@null</item> -->
<item name="actionBarStyle">@style/ActionBarStyle.Transparent</item>
<item name="windowActionBarOverlay">true</item>
<item name="actionBarDivider">@color/black</item>
<item name="actionBarTabTextStyle">@style/TabTextStyle</item>
<item name="actionBarTabBarStyle">@color/black</item>