Just use in your Layout (it works also with the androidx.appcompat.widget.Toolbar
) the style:
<com.google.android.material.appbar.MaterialToolbar
style="@style/Widget.MaterialComponents.Toolbar.Primary"
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>
with:
<style name="MyToolbar" parent="Widget.MaterialComponents.Toolbar.Primary">
<item name="titleTextColor">@color/.....</item>
</style>
and the define the color in the values/colors.xml
and values-night/colors.xml
.
Or just apply a style in the Toolbar
<com.google.android.material.appbar.MaterialToolbar
style="@style/MyToolbar"
or simply override the theme with:
<com.google.android.material.appbar.MaterialToolbar
android:theme="@style/MyThemeOverlay_Toolbar"
with:
<style name="MyThemeOverlay_Toolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="colorOnPrimary">@color/...</item>
</style>