【问题标题】:Unable to set the custom text color of Actionbar Tabs无法设置操作栏选项卡的自定义文本颜色
【发布时间】:2014-07-21 19:16:01
【问题描述】:

我正在使用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>>

drawable/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" />

【问题讨论】:

标签: android xml android-actionbar customization


【解决方案1】:
<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 2015-12-17
    相关资源
    最近更新 更多