问题描述
我正在制作一个Android应用。我已经在其中使用了侧面导航抽屉,但没有看到抽屉中的颜色图标,但是我使用了颜色图标
我的XML代码是:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:context=".MainActivity"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/background_pic"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<FrameLayout
android:id="@+id/fragment_container"
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"
app:headerLayout="@layout/nav_header"
app:iconTint="@null"
app:menu="@menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
解决方法
使用:
navigationView.setItemIconTintList(null)
或在布局中使用 app:itemIconTint
而不是app:iconTint
<com.google.android.material.navigation.NavigationView
app:itemIconTint="@null"
,
错误
app:iconTint="@null"
使用您要使用的color
名称/代码
使用它
app:itemIconTint="@null"
如果您使用的是SVG
DrawableCompat.setTint(
DrawableCompat.wrap(myImageView.getDrawable()),ContextCompat.getColor(context,R.color.another_nice_color)
);