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
You can change the color of individual path at runtime, without using reflection.
VectorMaster introduces dynamic control over vector drawables. Each and every aspect of a vector drawable can be controlled dynamically (via Java instances), using this library.
Just add the following dependency in your app's build.gradle
dependencies {
compile 'com.sdsmdg.harjot:vectormaster:1.0.9'
}
In your case you need a simple color change:
Vector example: your_vector.xml
XML:
Java:
VectorMasterView heartVector = (VectorMasterView)
findViewById(R.id.your_drawable);
// find the correct path using name
PathModel outline = heartVector.getPathModelByName("outline");
// set the stroke color
outline.setStrokeColor(Color.parseColor("#ED4337"));
// set the fill color (if fill color is not set or is TRANSPARENT, then no fill is drawn)
outline.setFillColor(Color.parseColor("#ED4337"));
From: https://github.com/harjot-oberai/VectorMaster, licensed under MIT.
You have now full control over vector drawables.