ActionBar标题颜色不会更改

时间:2013-02-12 14:43:14

标签: android android-actionbar

我想将操作栏的标题颜色更改为白色。我已经在样式上声明了:

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!--
    Theme customizations available in newer API levels can go in
    res/values-vXX/styles.xml, while customizations related to
    backward-compatibility can go here.
-->
</style>

<!-- Application theme -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowActionBar">true</item>
<item name="android:actionBarStyle">@style/ProjActionBar</item>
<item name="android:actionBarTabTextStyle">@style/ProjActionBar.TitleTextStyle</item>
</style>

<!-- ActionBar Style -->
<style name="ProjActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@color/b</item>
    <item name="android:backgroundStacked">@color/k1</item>
    <!-- This is when tabs are splitted into a second line -->
</style>

<style name="ProjActionBar.TitleTextStyle" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/w</item>
    <item name="android:textSize">13sp</item>
</style>

正如您所看到的,我将一个“actionBarTabTextStyle”用属性“textColor”声明为在我的colors.xml中声明的@ color / w:

<color name="w">#FFFFFFFF</color>

发生什么事了?为什么动作栏标题不会改变textColor?

我的项目针对的是最低版本的SDK 11 sdkVersion 17(Honeycomb 3.0 +)

1 个答案:

答案 0 :(得分:6)

问题是您实际上没有更改标题文字样式。您已更改选项卡文本的样式。要更改标题文字样式,您需要在android:titleTextStyle样式上设置android:subtitleTextStyleProjActionBar

所以,你的ProjActionBar就变成了这个:

<style name="ProjActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@color/b</item>
    <item name="android:backgroundStacked">@color/k1</item>
    <item name="android:titleTextStyle">@style/ProjActionBar.TitleTextStyle</item>
</style>

请注意,这假设您使用的是本机ActionBar组件(正如您从@android:style/Widget.Holo.Light.ActionBar继承的那样)。如果您想要向后兼容,则必须从Widget.AppCompat.Light.ActionBar继承您的样式并使用textStyle代替android:textStyle