Change specific icon's color in NavigationDrawer

▼魔方 西西 提交于 2019-12-12 03:16:43

问题


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);


来源:https://stackoverflow.com/questions/38915607/change-specific-icons-color-in-navigationdrawer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!