How to change text color of action bar title on Android 4.3 api 18

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

The color of the title text changes in GingerBread, but when I run the application on my phone with JellyBean, the color does not change.

In the header color, GingerBread changes to red:

enter image description here

On JellyBean it stays 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" 
+4
source share
2 answers

Found a solution to my problem:

I need to use android:actionBarStyle, android:titleTextStyleand android:textColorfor level 14 and above.

, styles.xml v-11 :

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

, ActionBar:

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

, , .

0

Source: https://habr.com/ru/post/1531343/


All Articles