androidandroid-toolbarandroid-appcompatandroid-stylesandroid-navigationview

How to change the navigation icon color


I have a navigationView in my app and after add two lines in app style :

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

The Navigation icon color changed to black and for this problem i added this line in style :

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

Now navigation icon is white again but now i have a new problem . With above code , the title of navigation items is change color too.

I didn't find a solution to this Interference

Style :

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:textColorSecondary">@android:color/white</item>

</style>

Navigation Menu :

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <group
        android:id="@+id/testGRP"
        android:checkableBehavior="single"
        >
    <item android:title="جلسه : انتخاب نشده"
        android:id="@+id/menuItem_StudentList11"
        android:icon="@drawable/ic_arrow_drop_up"
        />

    <item android:title="مرتب سازی"
        android:id="@+id/menuItem_StudentList_Quize1"
        android:icon="@drawable/all_exam_icon"
        />

        <item android:title="@string/Navigation_StudentList3"
            android:id="@+id/menuItem_StudentList_Quize"
            android:icon="@drawable/all_exam_icon"
            />

    </group>


    <item android:title="رویدادها:"> //this line is title

    <menu>

    <item android:title="@string/Navigation_StudentList4"
        android:id="@+id/menuItem_StudentList_MidTerm"
        android:icon="@drawable/all_exam_icon"
        />

    <item android:title="@string/Navigation_StudentList5"
        android:id="@+id/menuItem_StudentList_EndTerm"
        android:icon="@drawable/all_exam_icon"
        />

    <item android:title="امتحان عملی"
        android:id="@+id/menuItem_StudentList_Practical"
        android:icon="@drawable/all_exam_icon"
        />


    <item android:title="@string/Navigation_StudentList6"
        android:id="@+id/menuItem_StudentList_Project"
        android:icon="@drawable/all_projcet_icon"
        />


    <item android:title="@string/Navigation_StudentList2"
        android:id="@+id/menuItem_StudentList_Conference"
        android:icon="@drawable/all_conference_icon"
        />
    </menu>
        </item>


    <item android:title="@string/Navigation_StudentList1"
        android:id="@+id/menuItem_StudentList1"
        android:icon="@drawable/all_notifiicon_icon"
        />

    <item android:title="@string/Navigation_StudentList7"
        android:id="@+id/menuItem_StudentList7"
        android:icon="@drawable/main_newclass_icon"
        />
</menu>

enter image description here

enter image description here


Solution

  • Using a Toolbar, to change the navigation icon color you can use:

    With a MaterialToolbar or (androidx and a Material theme):

    <com.google.android.material.appbar.MaterialToolbar
        android:theme="@style/MyThemeOverlay_Toolbar"
        ...>
    
      <style name="MyThemeOverlay_Toolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
        <!-- color used by navigation icon and overflow icon -->
        <item name="colorOnPrimary">@color/secondaryColor</item>
      </style>
    

    With the support Library:

    <android.support.v7.widget.Toolbar
      app:theme="@style/ThemeToolbar" />
    
    
    <style name="ThemeToolbar" parent="Theme.AppCompat.Light">
       <!-- navigation icon color -->
       <item name="colorControlNormal">@color/my_color</item>
    </style>