Konrad
Konrad

Reputation: 72

How to change text color in Action bar using theme and Theme.AppCompat.DayNight

I am trying to change the text color of the text in Default Action Bar using Theme. I can easily change the background of the Status Bar, but whatever I do, the text stays the same in Action Bar:

enter image description here

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.MyAapp" parent="Theme.AppCompat.DayNight">
    <!-- Primary brand color. -->

    <item name="colorPrimary">@color/ocean</item>
    <item name="colorPrimaryVariant">@color/light_ocean</item>
    <item name="colorOnPrimary">@color/white</item>
    <!-- Secondary brand color. -->
    <item name="colorSecondary">@color/ocean</item>
    <item name="colorSecondaryVariant">@color/dark_ocean</item>
    <item name="colorOnSecondary">@color/ocean</item>
    <!-- Status bar color. -->
    <!-- Status bar color. -->
    <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
    <!-- Customize your theme here. -->
</style>

Is it possible to override it in Theme.AppCompat.DayNight? I need to use this theme. I will appreciate your help.

Upvotes: 1

Views: 1775

Answers (3)

Houssin Boulla
Houssin Boulla

Reputation: 2869

You need to define toolbar_style with parent: Widget.AppCompat.ActionBar like this example:

<style name="AppTheme" parent="Theme.AppCompat.Light">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primaryDark</item>
        <item name="colorAccent">@color/highlightRed</item>
        <item name="actionBarTheme">@style/toolbar_style</item>
</style>


<style name="toolbar_style" parent="Widget.AppCompat.ActionBar">
        <item name="android:textColorPrimary">@color/white</item>
</style>

Upvotes: 1

Sina Moradi
Sina Moradi

Reputation: 61

Hello this is a map for you. If you do not have some of them, you must define it

this is a map for you

Upvotes: 3

Raluca
Raluca

Reputation: 51

    <!-- Base application theme. -->
    <style name="Theme.MyAapp" parent="Theme.AppCompat.DayNight">
        <!-- Primary brand color. -->

        <item name="colorPrimary">@color/ocean</item>
        <item name="colorPrimaryVariant">@color/light_ocean</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/ocean</item>
        <item name="colorSecondaryVariant">@color/dark_ocean</item>
        <item name="colorOnSecondary">@color/ocean</item>
        <!-- Status bar color. -->
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->

        <item name="android:actionBarStyle">@style/ThemeOverlay.MaterialComponents.ActionBar</item>
    </style>

    <style name="hemeOverlay.MaterialComponents.ActionBar"  parent="ThemeOverlay.MaterialComponents.Dark.ActionBar">
        <item name="android:textColor">@color/black</item>
    </style>

Upvotes: 1

Related Questions