MagogCZ
MagogCZ

Reputation: 93

Change ActionBar text color after inheriting Theme.AppCompat.DayNight

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.

Upvotes: 6

Views: 4321

Answers (3)

Alessandro Scarozza
Alessandro Scarozza

Reputation: 4438

need to use actionBarTheme and not actionBarStyle for text Color

Upvotes: 0

Quwaysim
Quwaysim

Reputation: 407

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

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

Upvotes: 4

Gabriele Mariotti
Gabriele Mariotti

Reputation: 365008

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>    

Upvotes: 12

Related Questions