Android - 如何在具有两种或多种颜色的矢量绘图上设置色调

问题描述 投票:0回答:2

我喜欢矢量绘图,事实上我可以使用简单的色调属性更改每个布局中的色调,如下所示:

<ImageView
            android:id="@+id/image_payment_cash"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:tint="@color/color1"
            android:src="@drawable/ic_cash" />

但我想知道是否有一种方法可以为同一向量(对于多色向量)指定两种或多种色调? 所以可以这样设置:

 <ImageView
            android:id="@+id/image_payment_cash"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:tint1="@color/color1"
            android:tint2 = "@color/color2"
            android:src="@drawable/ic_cash" />
android android-layout android-drawable android-resources android-vectordrawable
2个回答
1
投票

不,默认情况下,无法在 XML 中为 Vector Drawable 的多种不同颜色着色。

您可以在 Java/Kotlin 中以编程方式将可绘制文件膨胀为 VectorDrawable 类,然后遍历每一层,然后单独更改颜色。
通过使用相同的代码,您可以创建一个具有“tint1”和“tint2”属性的自定义 ImageView。

如果您使用 API 21 以下的 Vector Drawables,请注意 Android 框架使用不同的类来反向移植某些 VD 元素。


0
投票

porterduff 模式无法帮助在图像中着色两种不同的颜色?

© www.soinside.com 2019 - 2024. All rights reserved.