为导航抽屉中的图标制作颜色

Make color of icon in navigation drawer

我正在努力学习Android,我正在尝试制作导航抽屉。

我的目标是实现这样的目标:

但我的结果是这样的:

这是我的 style.xml:

    </style>

    <style name="Base.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/md_deep_purple_500</item>
        <item name="colorPrimaryDark">@color/md_deep_purple_700</item>
        <item name="colorAccent">@color/md_white_1000_50</item>
    </style>

    <style name="ToolbarTheme" parent="AppTheme">
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
    </style>

    <style name="NavigationViewTheme" parent="AppTheme">
        <item name="textAppearanceListItem">@style/TextAppearance.AppCompat.Body2</item>
        <item name="android:icon">@style/Theme.AppCompat.Light</item>
    </style>
</resources>

这是我的 navigation_drawer_header:

<?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="16dp"
        android:gravity="bottom"
        android:theme="@style/ThemeOverlay.AppCompat.Light"
        >
</FrameLayout>

任何人都可以向我建议如何更正这些吗?

这是因为 NavigationView 为图标添加了色调。 为避免这种情况,您可以添加

navigationView.setItemIconTintList(null);

您可以添加颜色状态列表。看看 this