REX
REX

Reputation: 149

Navigation icon color in toolbar is not changing?

I have a Material toolbar with a navigation icon added to it. However, when I try to change the navigation icon colour the changes are visible in Layout validation but not when I install the app on my phone.

Here is the link to the toolbar photo toolbar image

Here is the xml Layout:

<com.google.android.material.appbar.MaterialToolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        app:title="Title Text"
        app:menu="@menu/main_activity"
        android:background="@color/color_toolbar"
        app:titleTextColor="@color/titleTextColor"
        app:navigationIcon="@drawable/ic_baseline_dehaze"
        app:navigationIconTint="@color/white"
        android:layout_height="wrap_content"/>

Navigation icon drawable (@drawable/ic_baseline_dehaze):

<vector android:height="24dp" android:tint="#FFFFFF"
        android:viewportHeight="24" android:viewportWidth="24"
        android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
        <path android:fillColor="@android:color/white" android:pathData="M2,15.5v2h20v- 
        2L2,15.5zM2,10.5v2h20v-2L2,10.5zM2,5.5v2h20v-2L2,5.5z"/>
</vector>

MainActivity.java:

public class MainActivity extends AppCompatActivity {

private MaterialToolbar toolbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);;
    setContentView(R.layout.activity_main);
    
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationIconTint(getResources().getColor(R.color.white));
}
}

Here is themes.xml:

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.NewApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <!-- Primary brand color. -->
    <item name="colorPrimary">@color/highlight</item>
    <item name="colorPrimaryVariant">@color/action_mode</item>
    <item name="colorOnPrimary">@color/white</item>
    <!-- Secondary brand color. -->
    <item name="colorSecondary">@color/checkIconselected</item>
    <item name="colorSecondaryVariant">@color/checkIconselected</item>
    <item name="colorOnSecondary">@color/black</item>
    <!-- Status bar color. -->
    <item name="android:statusBarColor" tools:targetApi="l">#00766a</item>
    <!-- Customize your theme here. -->
    <item name="actionModeBackground">@color/action_mode</item>
    <item name="windowActionModeOverlay">true</item>
</style>

Here is colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>

<color name="color_toolbar">#075e54</color>
<color name="activityBackground">#ffffff</color>
<color name="titleTextColor">#ffffff</color>
<color name="highlight">#075e54</color>
<color name="selected">#8A354239</color>
<color name="checkIconselected">#25D366</color>
<color name="transparent">#00FFFFFF</color>
<color name="action_mode">#00897b</color>
<color name="toolbar_bg">#8A000000</color>
<color name="tab_indicator">#ffffff</color>
<color name="white_black">#000000</color>
</resources>

So if you can see I have changed the navigation icon colour in both drawable and activity.java, the colour is still not changing. Can someone tell me what mistake I am doing?

Upvotes: 2

Views: 1285

Answers (1)

Sadegh J
Sadegh J

Reputation: 1862

you can add this line to your style:

    <item name="android:textColorSecondary">INSERT_COLOR_HERE</item>

or create another style with this item and set that to toolbar:

<style name="ToolbarColor" parent="AppTheme">
<item name="android:textColorSecondary">INSERT_COLOR_HERE</item>
</style>


 <com.google.android.material.appbar.MaterialToolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    app:title="Title Text"
    app:menu="@menu/main_activity"
    android:background="@color/color_toolbar"
    app:titleTextColor="@color/titleTextColor"
    app:navigationIcon="@drawable/ic_baseline_dehaze"
    app:navigationIconTint="@color/white"
    android:layout_height="wrap_content"/
    app:theme="@style/ToolbarColor">

Also you can set colorControlNormal instead android:textColorSecondary

Upvotes: 5

Related Questions