PainterResource() 用黑色绘制我的矢量

Has*_*ssa 2 android kotlin android-jetpack-compose

好的,我已经创建了自己的 .SVG 矢量图标并将其作为 XML 导入 Android Studio。现在我正在尝试使用相同的向量创建一个图标。但是,当我在 PainterResource() 中指定该向量时,它会将其绘制为黑色。而我原来的 SVG 有多种颜色。为什么会发生这种情况?

Icon(
     painter = painterResource(id = R.drawable.ic_google_logo),
     contentDescription = "Google Button"
    )
Run Code Online (Sandbox Code Playgroud)

当我添加该图标时,我看到的是: 在此处输入图片说明

这就是该图标的实际显示方式: 在此处输入图片说明

Ste*_*ack 17

老实说,我认为接受的答案不是正确的做法。图标自动着色为必要的上下文颜色。

如果您想显示不着色的图标,我建议使用图像:

Image(
    painter = painterResource(id = R.drawable.ic_google_logo),
    contentDescription = "Google Button"
)
Run Code Online (Sandbox Code Playgroud)


Gab*_*tti 5

Icon应用默认的色彩(LocalContentColor.current.copy(alpha = LocalContentAlpha.current)

使用tint= Color.Unspecified以避免它:

Icon(
     painter = painterResource(id = R.drawable.ic_google_logo),
     contentDescription = "Google Button",
     tint= Color.Unspecified
    )
Run Code Online (Sandbox Code Playgroud)