2016-09-28 82 views

回答

1

你可以简单地使用

android:fillColor="@color/colorRated" 

但它可能不适用于一些低安卓版本的设备。这就是为什么我通常使用直接的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> 
0

您需要使用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"/> 
1

临语法,

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,它们在较低的设备上不起作用。

相关问题