I am having some trouble with vectors drawable on older API version in Android. I need to change drawables at runtime each time the activity starts should load the corresponding svg file.
This is my layer list :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="oval">
<size android:height="50dp" android:width="50dp"/>
<!-- fill color -->
<solid android:color="@color/white" />
</shape>
</item>
<item
android:id="@+id/avatar"
android:drawable="@drawable/dog" //I need to change this at run time
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp"/>
In my activity, I am using
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
So far I am using layer drawable to pick the xml file and change the svg but I am having compatibility issues as layerDrawable.setDrawble()
is only available in API level >= 23
layerDrawable = (LayerDrawable) ContextCompat.getDrawable(this, R.drawable.seekbar_thumb);
Drawable avatar = (Drawable) ContextCompat.getDrawable(this, getUserAvatarId());
layerDrawable.setDrawable(0, avatar);