Search code examples
androidandroid-actionbartextcolor

AppCompat: ActionBar change textColor and style?


I noticed a lot of people ask this question, and I change my code follow this answer: How to set bold title in Action Bar?

However, I can't change title color to red and style to bold. This is my code link in github:

https://github.com/fhlkm/TitleStyle.git

And this is my Style.xml code:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBar</item>
    <item name="actionBarStyle">@style/MyTheme.ActionBar</item>
</style>

<style name="MyTheme.ActionBar" parent="Widget.AppCompat.ActionBar.Solid">
    <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="TextAppearance.AppCompat">
    <item name="android:background">#ff0000</item>
    <item name="android:textStyle">bold</item>
</style>

This is the screenshot: enter image description here


Solution

  • I don't know why but after I change from parent="TextAppearance.AppCompat" to parent="Widget.AppCompat.ActionBar.TabText", the color and textStyle is changed, this is the new xml:

        <style name="AppTheme" parent="Theme.AppCompat.Light">
        <item name="actionBarStyle">@style/ActionBarCompat</item>
    </style>
    
    <style name="ActionBarCompat" parent="Widget.AppCompat.ActionBar.Solid">
        <item name="titleTextStyle">@style/titleStyle</item>
    </style>
    
    <style name="titleStyle" parent="Widget.AppCompat.ActionBar.TabText">
        <item name="android:textColor">@android:color/holo_blue_dark</item>
        <item name="android:textStyle">bold</item>
    </style>