How to change color of vector drawable path on button click

后端 未结 9 1795
北荒
北荒 2020-12-01 00:33

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

9条回答
  •  悲&欢浪女
    2020-12-01 01:24

    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); 
    

    Library is here: https://github.com/devsideal/VectorChildFinder

提交回复
热议问题