Navigation drawer menu icon is not displayed corre

2019-03-25 14:19发布

I want to input my customized icon into the menu in navigation drawer. However, when I run the application it only display a shadow of icon. How do I show the image correctly?

enter image description here

Here is the xml file for menu activity_main_drawer.xml:

<?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/recent_picture"
            android:icon="@mipmap/ic_recent"
            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>
</menu>

Here is the xml layout with the navigation view:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>

There is another drawables.xml files found in the values folder.

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<item name="ic_recent_picture" type="drawable">@mipmap/ic_recent</item>
<item name="ic_menu_gallery" type="drawable">@drawable/ic_menu_gallery</item>
<item name="ic_menu_slideshow" type="drawable">@android:drawable/ic_menu_slideshow</item>
<item name="ic_menu_manage" type="drawable">@android:drawable/ic_menu_manage</item>
<item name="ic_menu_share" type="drawable">@android:drawable/ic_menu_share</item>
<item name="ic_menu_send" type="drawable">@android:drawable/ic_menu_send</item>

3条回答
地球回转人心会变
2楼-- · 2019-03-25 14:49

if you still haven't solved the problem by removing the tint, you might want to move your resource file to drawable (use Poject View) instead of drawable-anydpi like I did

查看更多
劳资没心,怎么记你
3楼-- · 2019-03-25 14:58

It works now by removing the tint effect from icon by setItemIconTintList(null). Put the line of code below under the navigationView.

 NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
 navigationView.setItemIconTintList(null);
 navigationView.setNavigationItemSelectedListener(this);
查看更多
做自己的国王
4楼-- · 2019-03-25 15:00

Did you try to change to another image to see if it is displaying?

<item name="ic_recent_picture" type="drawable">@mipmap/ic_recent</item>

Path @mipmap contains correct image?

查看更多
登录 后发表回答