如何在按钮单击时更改矢量可绘制路径的颜色 [英] How to change color of vector drawable path on button click

查看:19
本文介绍了如何在按钮单击时更改矢量可绘制路径的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着新的 android 支持更新,矢量可绘制对象获得向后兼容性.我有一个带有各种路径的矢量图像.我希望路径的颜色在单击按钮时或根据输入值以编程方式更改.是否可以访问矢量路径的名称参数?然后改变颜色.

With the new android support update, vector drawables get backward compatibility. I have a vector image with various paths. I want the color of the paths to change on click of a button or programmatically based on an input value. Is it possible to access the name parameter of the vector path? And then change the color.

推荐答案

使用它来更改矢量可绘制对象中的路径颜色

Use this to change a path color in your vector drawable

VectorChildFinder vector = new VectorChildFinder(this, R.drawable.my_vector, imageView);

VectorDrawableCompat.VFullPath path1 = vector.findPathByName("path1");
path1.setFillColor(Color.RED); 

图书馆在这里:https://github.com/devsideal/VectorChildFinder

这篇关于如何在按钮单击时更改矢量可绘制路径的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆