简体   繁体   中英

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, 在此处输入图片说明

please tell what to do and why its happening..

As always thanks a lot..

尝试删除项目图标的色彩。

mNavigationView.setItemIconTintList(null);

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" 
    ... />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM