在 Android Studio 中更改矢量资产的填充颜色 [英] Change fill color on vector asset in Android Studio
本文介绍了在 Android Studio 中更改矢量资产的填充颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Android Studio 现在支持 21 岁以上的矢量资源,并会在编译时为较低版本生成 png.我有一个矢量资产(来自 Material Icons),我想更改填充颜色.这适用于 21+,但生成的 png 不会改变颜色.有没有办法做到这一点?
Android Studio now supports vector assets on 21+ and will generate pngs for lower versions at compile time. I have a vector asset (from the Material Icons) that I want to change the fill color. This works on 21+, but the generated pngs do not change color. Is there a way to do this?
<vector android:height="48dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/primary" android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
推荐答案
不要直接编辑矢量资源.如果您在 ImageButton 中使用矢量可绘制对象,只需在 android:tint
中选择您的颜色.
Don't edit the vector assets directly. If you're using a vector drawable in an ImageButton, just choose your color in android:tint
.
<ImageButton
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/button"
android:src="@drawable/ic_more_vert_24dp"
android:tint="@color/primary" />
这篇关于在 Android Studio 中更改矢量资产的填充颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文