VectorRuntime is a lightweight Android library that allows you to change VectorDrawable colors and strokes at runtime without editing XML files.
- Change path fill colors.
- Change stroke colors and widths.
- Modify paths using an index or name.
- No XML changes required.
- Simple Java API.
- Automatically redraw updated vectors.
Add the library module to your build.gradle.kts file:
dependencies {
implementation(project(":vtruntime"))
}First, load your vector drawable from resources.
Antik antik = Antik.load(this, R.drawable.user);Change the fill color of the first path.
antik.setPathColor(0, Color.BLACK);Path indexes start from 0.
Set the stroke color of the first path.
antik.setStrokeColor(0, Color.WHITE);Set the stroke width of the first path.
antik.setStrokeWidth(0, 2.0f);Apply the updated drawable to your ImageView.
antik.into(mImage);You can also change a path color using its XML name.
Example XML:
<path
android:name="bg_circle"
android:fillColor="#FF905D4C"
android:pathData="..." />Java:
Antik antik = Antik.load(this, R.drawable.user);
antik.setPathColor("bg_circle", Color.RED);
antik.into(mImage);| Method | Description |
|---|---|
Antik.load(context, resId) |
Load a vector drawable |
setPathColor(index, color) |
Change fill color by index |
setPathColor(name, color) |
Change fill color by name |
setStrokeColor(index, color) |
Change stroke color by index |
setStrokeColor(name, color) |
Change stroke color by name |
setStrokeWidth(index, width) |
Change stroke width by index |
setStrokeWidth(name, width) |
Change stroke width by name |
getPathCount() |
Get total number of paths |
getPathColor(index) |
Get path color by index |
getPathColor(name) |
Get path color by name |
getDrawable() |
Get the drawable |
into(imageView) |
Set drawable to ImageView |
VectorRuntime loads a VectorDrawable and allows you to modify its individual paths.
After a path is changed, the drawable is automatically updated and redrawn.
Based on Android Open Source Project components. See the source files for license details.
