如何以编程方式设置组合矢量图标的色调模式和色调颜色

MAR*_*RK 7 android-vectordrawable android-jetpack-compose

我有一些从 SVG 转换而来的矢量图标,我需要根据某些条件为它们自定义色调颜色,我正在尝试以编程方式更改色调颜色

Image(
        modifier = Modifier.size(128.dp),
        painter = painterResource(id = R.drawable.icon_1),
        contentDescription = null,
        colorFilter =  ColorFilter.tint(Color.Red)
    )
Run Code Online (Sandbox Code Playgroud)

它给了我以下结果

结果

另外,当我尝试使用

Image(
    modifier = Modifier.size(128.dp),
    painter = painterResource(id = R.drawable.icon_1),
    contentDescription = null,
    colorFilter =  ColorFilter.tint(Color.Red, blendMode = BlendMode.Multiply)
)
Run Code Online (Sandbox Code Playgroud)

我也得到了同样的结果。但是,当我尝试通过添加来更改 XML 文件中的图标色调时

android:tint="@color/red"
android:tintMode="multiply"
Run Code Online (Sandbox Code Playgroud)

它正确地给了我想要的结果,如下所示

在此输入图像描述

那么,当我需要根据某些条件以编程方式将颜色更改为不同颜色时,如何才能以编程方式实现相同的结果呢?

MAR*_*RK 5

我能够通过使用来修复它blendMode = BlendMode.Modulate

    Image(
        modifier = Modifier.size(128.dp),
        painter = painterResource(id = resultType.resId),
        contentDescription = null,
        colorFilter = ColorFilter.tint(color = Color.Red, blendMode = BlendMode.Modulate) }
    )
Run Code Online (Sandbox Code Playgroud)