0

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

<!--
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”声明为@color/w,在我的colors.xml中声明为:

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

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

我的项目针对 min SDK 11 sdkVersion 17 (Honeycomb 3.0+)

4

1 回答 1

6

问题是您实际上并没有更改标题文本样式。您已更改选项卡文本的样式。要更改标题文本样式,您需要设置样式,android:titleTextStyle并且可以选择android:subtitleTextStyle设置ProjActionBar

所以,你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.

于 2013-02-12T14:49:02.197 回答