导航抽屉菜单图标显示不正确

编程入门 行业动态 更新时间:2024-10-16 00:20:50
本文介绍了导航抽屉菜单图标显示不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将我的自定义图标输入到导航抽屉的菜单中.但是,当我运行该应用程序时,它只显示图标的阴影.如何正确显示图片?

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?

这是菜单 activity_main_drawer.xml 的 xml 文件:

Here is the xml file for menu activity_main_drawer.xml:

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="schemas.android/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>

这是带有导航视图的 xml 布局:

Here is the xml layout with the navigation view:

<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="schemas.android/apk/res/android" xmlns:app="schemas.android/apk/res-auto" xmlns:tools="schemas.android/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>

在 values 文件夹中有另一个 drawables.xml 文件.

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

<resources xmlns:android="schemas.android/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>

推荐答案

它现在可以通过 setItemIconTintList(null) 去除图标的色调效果.将下面的代码行放在 navigationView 下.

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

更多推荐

导航抽屉菜单图标显示不正确

本文发布于:2023-11-25 00:23:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627538.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不正确   抽屉   图标   菜单

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!