删除 jetpack compose 中 IconButton 的黑色色调

Viv*_*odi 4 android kotlin android-drawable android-jetpack android-jetpack-compose

我在代码中使用IconButton。我使用了不同颜色的drawable。当我运行代码时,它显示黑色思考。那么这里出了什么问题呢?

IconButton(
    onClick = {  }
) {
    Icon(
        painter = painterResource(R.drawable.ic_menu),
        contentDescription = null,
    )
}
Run Code Online (Sandbox Code Playgroud)

实际产量

在此输入图像描述

预期输出

在此输入图像描述

我在这里分享我的可绘制文件

ic_menu.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="20dp"
    android:height="4dp"
    android:viewportWidth="20"
    android:viewportHeight="4">
    <path
        android:fillColor="@color/aqua"
        android:fillType="evenOdd"
        android:pathData="M2,2m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0" />
    <path
        android:fillColor="@color/aqua"
        android:fillType="evenOdd"
        android:pathData="M10,2m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0" />
    <path
        android:fillColor="@color/aqua"
        android:fillType="evenOdd"
        android:pathData="M18,2m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0" />
</vector>
Run Code Online (Sandbox Code Playgroud)

MoN*_*oNe 7

如果您想使用原始图标颜色而不使用任何默认色调,则需要传入tint = Color.UnspecifiedIcon

例子:

Icon(
    painter = painterResource(R.drawable.ic_menu),
    tint = Color.Unspecified,
    contentDescription = null
 )
Run Code Online (Sandbox Code Playgroud)

根据官方文档,当您不提供任何色调时,Icon 对所有资源使用默认的黑色色调。

图标

正如您所看到的,它默认使用LocalContentColorWhich is black 。

本地内容颜色