本文介绍了在Android Studio中更改矢量素材的填充颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Android Studio现在在21+上支持矢量资产,并将在编译时为较低版本生成png.我有一个矢量素材(来自材质图标"),我想更改填充颜色.这适用于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中更改矢量素材的填充颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!