[Solved] How to change toolbar text color from MaterialComponents.DayNight theme?

I am using MaterialComponents.DayNight theme in my app. In the day mode, toolbar text color is black. But when I switch to night mode toolbar text color is remain black, so it’s not visible anymore.

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">

I want to change the toolbar text color into white in night mode. How can I do that?

Solution #1:

Just use in your Layout (it works also with the androidx.appcompat.widget.Toolbar) the style:


Then define in the values-night/colors.xml the colorOnPrimary.

Then there are a lot of alternatives.
You can customize globally the style of the toolbar in the app theme with:

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


  <style name="MyToolbar" parent="Widget.MaterialComponents.Toolbar.Primary">
    <item name="titleTextColor">@color/.....</item>

and the define the color in the values/colors.xml and values-night/colors.xml.

Or just apply a style in the Toolbar


or simply override the theme with:



  <style name="MyThemeOverlay_Toolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
    <item name="colorOnPrimary">@color/...</item>
Respondent: Gabriele Mariotti

Solution #2:

Add this entry to your theme:

<item name="android:itemTextAppearance">@style/PopupMenuTextAppearance</item>

After that, add the style accordingly to the styles.xml:

<style name="PopupMenuTextAppearance" parent="TextAppearance.AppCompat.Menu">
    <item name="android:textColor">?attr/colorOnBackground</item>

?attr/colorOnBackground is available in the Material Components library. If you’re not using that, you should be able to use ?android:attr/textColorPrimary instead.

Solution #3:

Set your parent theme to parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge"

By using this, you will keep your ActionBar’s original theme with DarkActionBar attributes on top of the overal DayNight theme from MaterialComponents.

Respondent: kevoroid

Solution #4:

in my opinion you should set the style on noActionbar and design new toolbar and customize it

Respondent: mohammad

Solution #5:

I used these two lines of code inside the styles.xml file:

<item name="colorControlNormal">@android:color/white</item>
<item name="android:textColorPrimary">@android:color/white</item>

It changed the color on the toolbar text and the toolbar X icon to white.

The whole code looked like this:

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">#00695c</item>
        <item name="colorPrimaryVariant">#439889</item>
        <item name="colorOnPrimary">#ffffff</item>
        <item name="colorSecondary">#007769</item>
        <item name="colorSecondaryVariant">#48a697</item>
        <item name="colorOnSecondary">#ffffff</item>
        <item name="colorControlNormal">@android:color/white</item>
        <item name="android:textColorPrimary">@android:color/white</item>
Respondent: carloswm85

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy