Change specific icon's color in NavigationDraw

2019-09-15 19:55发布

问题:

I have a problem with changing the icon's color in default Drawer Menu in Android, there are lots of topics but they only explain changing the tint color of whole menu not a specific icon:

For example I want to change the color of Favorites icon to yellow

回答1:

You can change icon of the menu from here like this from activity_drawer_drawer.xml layout

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android">

        <group android:checkableBehavior="single">
            <item
                android:id="@+id/nav_camera"
                <!-- Change your drawable here -->
                android:icon="@drawable/ic_menu_camera"
                android:title="Import"/>
            <item
                android:id="@+id/nav_gallery"
                android:icon="@drawable/ic_menu_gallery"
                android:title="Gallery"/>
            <item
                android:id="@+id/nav_slideshow"
                android:icon="@drawable/ic_menu_slideshow"
                android:title="Slideshow"/>
            <item
                android:id="@+id/nav_manage"
                android:icon="@drawable/ic_menu_manage"
                android:title="Tools"/>
        </group>

        <item android:title="Communicate">
            <menu>
                <item
                    android:id="@+id/nav_share"
                    android:icon="@drawable/ic_menu_share"
                    android:title="Share"/>
                <item
                    android:id="@+id/nav_send"
                    android:icon="@drawable/ic_menu_send"
                    android:title="Send"/>
            </menu>
        </item>

    </menu>

To remove tint color effect use this

mNavigationView.setItemIconTintList(null);