[英]Icons are not visible in navigation drawer
enter image description here While designing the main navigation for an app, the icons are not visible.在此处输入图像描述 在设计应用程序的主导航时,图标不可见。 The tint is black default and is not getting changed.色调默认为黑色,不会更改。
Here is my code这是我的代码
<include
android:id="@+id/app_bar_main"
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.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"
android:background="@drawable/side_nav_bar"
app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
When I code like this the icons are visible当我这样编码时,图标可见
<include
android:id="@+id/app_bar_main"
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.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"
android:background="@drawable/side_nav_bar"
app:itemIconTint=""
app:menu="@menu/activity_main_drawer" />
Menus do not support coloured images菜单不支持彩色图像
You can not use a coloured image in these places and a bit more also:你不能在这些地方使用彩色图像,还有更多:
Basically which ever view uses a menu file for its resource, cannot have a coloured image.基本上,哪个视图使用菜单文件作为其资源,不能有彩色图像。 That is why you don't see it.这就是为什么你看不到它。 To test it yourself, take a colourful image in your drawable and set it as an icon for the navigation drawer.要自己进行测试,请在可绘制对象中获取彩色图像并将其设置为导航抽屉的图标。 You notice that it comes the same way.你注意到它的出现方式相同。 This proves it这证明了
But, there are also some alternatives.但是,也有一些替代方案。
You can do it this way:你可以这样做:
mNavDrawer.setItemIconTintList(null);
or in Kotlin:或在 Kotlin 中:
mNavDrawer.itemIconTintList = null;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.