In the code I am calling diamond.xml
with this string:
private final Drawable diamond = context.getResources().getDrawable(R.drawable.diamond);
I draw that with this code:
diamond.setBounds(0, 0, 10, 10);
diamond.draw(canvas);
In some cases, I need to draw that just changing one or both of the android:fillColor
. Is it possible? I would like to avoid to create N copies of diamond.xml
with all the combinations of colors.
diamond.xml
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="100dp" android:width="70dp"
android:viewportHeight="100" android:viewportWidth="100">
<path
android:fillColor="#FF5722"
android:pathData="M 5,5 95,5 95,95 5,95 z"
android:strokeAlpha="1"
android:strokeColor="#FFFFFF"
android:strokeLineCap="butt"
android:strokeLineJoin="round"
android:strokeWidth="4"/>
<path
android:fillColor="#8BC34A"
android:pathData="m 50,30 l 20,20 -20,20 -20,-20 z"
android:strokeAlpha="1"
android:strokeColor="#FFFFFF"
android:strokeLineCap="butt"
android:strokeLineJoin="round"
android:strokeWidth="4"/>
</vector>