Search code examples
javaandroidandroid-actionbarmaterial-components-androidmaterial-components

I want to change title bar text color in material Components theme. Any help will be greatly appreciated


I tried set title color but it is deprecated. I tried to change color by using

  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <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/red</item>
  </style>

as mentioned here: ActionBar text color but the whole Titlebar color changes to white while doing it. All I want to do is set my Black Title bar text color to white. I also tried this solution here: Change color title bar but I am using the MaterialComponents theme and using AppCompactThemes makes my app crash.


Solution

  • just add this to you base theme

     <item name="titleTextColor">@android:color/holo_red_dark</item> //whatever color
    

    Eg:

    <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.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="titleTextColor">@android:color/holo_green_dark</item>
    
        </style>