[英]Icons are not visible in navigation drawer
在此处输入图像描述 在设计应用程序的主导航时,图标不可见。 色调默认为黑色,不会更改。
这是我的代码
<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>
当我这样编码时,图标可见
<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" />
菜单不支持彩色图像
你不能在这些地方使用彩色图像,还有更多:
基本上,哪个视图使用菜单文件作为其资源,不能有彩色图像。 这就是为什么你看不到它。 要自己进行测试,请在可绘制对象中获取彩色图像并将其设置为导航抽屉的图标。 你注意到它的出现方式相同。 这证明了
但是,也有一些替代方案。
你可以这样做:
mNavDrawer.setItemIconTintList(null);
或在 Kotlin 中:
mNavDrawer.itemIconTintList = null;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.