我想设置颜色代码在矢量绘图从colors.xml文件的res文件夹。
发布于 2016-09-28 03:29:33
您可以简单地使用
android:fillColor="@color/colorRated"
但它可能不适用于某些低android版本的设备。这就是为什么我通常使用直接的xml颜色。
android:fillColor="#9ec8e6"
所以,最后看起来是:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="24"
android:viewportHeight="24"
android:width="48dp"
android:height="48dp">
<path
android:pathData="M23.7 12A11.7 11.7 0 0 1 12 23.7 11.7 11.7 0 0 1 0.30000019 12 11.7 11.7 0 0 1 12 0.30000019 11.7 11.7 0 0 1 23.7 12Z"
android:fillColor="#9ec8e6" />
</vector>
发布于 2016-09-28 03:32:52
从语法上讲,
DrawableCompat.setTint(myImageView.getDrawable(), ContextCompat.getColor(context, R.color.your_color));
或者通过xml使用fillColor
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="@color/your_color"
android:pathData="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" />
注意:使用硬编码的颜色(即#000
)而不是@color/your_color
,因为有时它们不能在较低的设备上工作。
发布于 2016-09-28 03:26:25
您需要使用android:tint="@color/some_color"
来填充矢量绘图上的颜色。
假设您有一个想要使用向量的ImageView
,您可以这样做
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bg_vector"
android:tint="@color/some_color"/>
https://stackoverflow.com/questions/39745961
复制相似问题