首页 > 解决方案 > 如何更改 kotlin 中的图标颜色?

问题描述

<?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:openDrawer="start">
    
        <include
            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"
            app:itemIconTint= ""
            app:menu="@menu/activity_main_drawer" />
    
    </androidx.drawerlayout.widget.DrawerLayout>

这些图标有它们原来的颜色。

但是,如果设置为 itemIconTint = "@null",则颜色变为灰色。

如果你删除@null,颜色会很好,但它不会被构建。

我是初学者。我应该怎么办?

在此处输入图像描述

我想让它变成这样。->在此处输入图像描述

标签: androidkotlincolorsiconsnavigationview

解决方案


通过阅读您所做的评论,我了解您不想更改图标的颜色。如果是这样,据我所知,根本不需要设置app:itemIconTint,它不是NavigationView. 你试过删除那条线吗?


推荐阅读