Search code examples
javaandroidandroid-actionbarmaterial-designandroid-theme

How to change Actionbar text color using Material Design?


I am using Material Design in my Android app and I want to change Actionbar text color and back button color.

This code is not working:

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowContentOverlay">@null</item>
    <!--<item name="android:textSize">3sp</item>-->
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>

</style>

<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/titleColor</item>
</style>

Solution

  • Using the ActionBar in your theme you can use:

     <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
            <item name="actionBarTheme">@style/ThemeOverlay.Actionbar</item>
     </style>
    
     <style name="ThemeOverlay.Actionbar" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" >
            <item name="android:textColorPrimary">@color/....</item>
     </style>
    

    enter image description here