4

I am using appcompat v7 library to support action bars in api level 8 and up. I am trying to change the color of title text of action bar.

Color of title text is changing in GingerBread but when I run the app on my phone with JellyBean the color doesn't change.

On GingerBread Title Color changes to Red:

enter image description here

On JellyBean it remains black:

enter image description here

Here are my styles.xml:

styles.xml:

<resources>

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
        <item name="actionBarStyle">@style/ActionBarStyle</item>
    </style>

    <style name="ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
        <item name="titleTextStyle">@style/TitleBarTextColor</item>
    </style>

    <style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/red</item>
    </style>
    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

styles.xml for v-11:

<resources>

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
        <item name="actionBarStyle">@style/ActionBarStyle</item>
    </style>

</resources>

styles.xml for v-14:

<resources>

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
        <item name="actionBarStyle">@style/ActionBarStyle</item>
    </style>
</resources>

Mainfest:

android:theme="@style/AppTheme" 
Rakesh
  • 1,133
  • 4
  • 13
  • 28

2 Answers2

15

Found Solution to my own problem :

I have to use android:actionBarStyle , android:titleTextStyle and android:textColor for api level 14 and up.

So the styles.xml for v-11 will be:

<resources>

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    </style>

    <style name="ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
        <item name="android:titleTextStyle">@style/TitleBarTextColor</item>
    </style>

    <style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/red</item>
    </style>
    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>
Rakesh
  • 1,133
  • 4
  • 13
  • 28
  • 1
    I don't know why but for me it's work only if I remove "android:" @style/MyActionBar @style/TitleBarTextColor – Anthone Feb 13 '15 at 17:59
0

I'll use the following within my styles for the current theme in order to update the text color in the ActionBar:

<item name="android:actionMenuTextColor">@color/Red</item>

which seems to work for me across the latest OS releases.

Jay Snayder
  • 4,298
  • 4
  • 27
  • 53
  • I only want to change the color of title thats why I have used TitleBarTextColor. I think your solution will effect the text on entire ActionBar like subtext, menu text etc. – Rakesh Mar 12 '14 at 14:01
  • You are right that is true. It modifies the entire ActionBar. Not sure if I have managed what you are asking in any of the applications I have worked upon (or had the need yet). – Jay Snayder Mar 12 '14 at 14:03