6

I'm implementing support for dark mode. But after I changed Theme parent to Theme.AppCompat.DayNight, text in Action Bar is black (black in day mode and white in dark mode). I want the text to be always white. I tried to change text color in styles.xml (values and values-night)

<style name="AppTheme" parent="Theme.AppCompat.DayNight">
  <item name="android:actionBarStyle">@style/MyActionBarStyle</item>
</style>

<style name="MyActionBarStyle" parent="Theme.AppCompat.DayNight.DarkActionBar">
  <item name="android:titleTextStyle">@style/MyActionBarTitleTextStyle</item>
</style>

<style name="MyActionBarTitleTextStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
  <item name="android:textColor">@color/white</item>
</style>

but it is not working. The title text color in ActionBar is still black.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
MagogCZ
  • 83
  • 2
  • 8

3 Answers3

11

Using the ActionBar in your theme you should use the actionBarStyle attribute:

<style name="AppTheme" parent="Theme.AppCompat.DayNight">
   <item name="actionBarStyle">@style/....</item>
</style>

<style name="MyActionBarStyle" parent="Theme.AppCompat.DayNight.DarkActionBar">
  <item name="titleTextStyle">@style/...</item>
</style>

If you are using the Toolbar API, you can also use

 <Toolbar
   app:titleTextColor="@color/...."
   ../>

Instead with the Material Components Library and the Toolbar API you can use:

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
   <item name="toolbarStyle">@style/my_Toolbar</item>
</style>

<style name=my_Toolbar" parent="@style/Widget.MaterialComponents.Toolbar">
    <item name="titleTextColor">@color/...</item>
</style>    
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
4

The best and easiest solution is @MagogCZ's answer =>

"works for me <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">" – MagogCZ

Quwaysim
  • 351
  • 3
  • 11
0

need to use actionBarTheme and not actionBarStyle for text Color

Alessandro Scarozza
  • 4,273
  • 6
  • 31
  • 39