How to change the navigation icon color
C

2

2

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

Clientele answered 24/9, 2019 at 6:21 Comment(3)
Are you using a toolbar in your layout?Particularize
Yes i use toolbarClientele
Its already answered here refer this answer.Velazquez
P
12

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>
Particularize answered 24/9, 2019 at 7:5 Comment(1)
Thanks. It worked like a charm.Steck
B
0

If you are looking to change text colors/appearance in the NavigationView Items, you should use the attribs

  • app:itemTextColor
  • app:itemIconTint
  • app:itemTextAppearance

Otherwise, Specify which view's color you want to change. Setting android:textColorSeconday is a bad idea according to me.

Bootlick answered 24/9, 2019 at 6:41 Comment(3)
My problem is the color of the navigationView icon, not the items and i don't find another way to change itClientele
Ok I get it now, That's the overflow icon, but not the navigationView iconBootlick
This will be changed by setting toolbar themeBootlick

© 2022 - 2024 — McMap. All rights reserved.