Search code examples
javaandroidandroid-menudrawerlayoutnavigation-drawer

set Image(PNG etc) as an icon on drawer layout navigation items


I'm setting the image as icon but its showing grey icon not the image,

This @drawable/image_second is the image I want to use as icon. image_second.png

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

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_home"
            android:icon="@drawable/image_second"
            android:title="@string/menu_home" />
        <item
            android:id="@+id/nav_gallery"
            android:icon="@drawable/ic_menu_gallery"
            android:title="@string/menu_gallery" />
        <item
            android:id="@+id/nav_slideshow"
            android:icon="@drawable/ic_menu_slideshow"
            android:title="@string/menu_slideshow" />
        <item
            android:id="@+id/nav_tools"
            android:icon="@drawable/ic_menu_manage"
            android:title="@string/menu_tools" />
    </group>

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

</menu>

after running the code,I get this, enter image description here

please tell what to do and why its happening..

As always thanks a lot..


Solution

  • You can do so programmatically using NavigationView.setItemIconTintList.

    yourNavigationView.setItemIconTintList(null);
    

    Also If you want to change the tint of other icons use this

    In XML

    <android.support.design.widget.NavigationView
        ...
        app:itemIconTint="@android:color/black" 
        ... />