简体   繁体   中英

ActionBar title color does not change

I want to change the title color of actionbar to white. I have declared on styles:

<!--
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>

As you can see I have a "actionBarTabTextStyle" declared with the attribute "textColor" to @color/w declared in my colors.xml as:

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

What happend? why the actionbar title does not change textColor?

My project is targeted to min SDK 11 sdkVersion 17 (Honeycomb 3.0+)

The problem is that you have not actually changed the title text style. You have changed the style of the tab text. To change the title text style, you want to set android:titleTextStyle and optionally android:subtitleTextStyle on your ProjActionBar style.

So, your ProjActionBar becomes this:

<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>

Please note that this assumes you are using the native ActionBar components (as indicated by the fact that you are inheriting from @android:style/Widget.Holo.Light.ActionBar ). If you want backwards compatibility, you will have to inherit your style from Widget.AppCompat.Light.ActionBar and use textStyle instead of android:textStyle .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM