I am super excited about the new possibility to set vector drawables to layouts using the app:srcCompat="@drawable/icon"
attribute introduced in support-library 23.2.0.
But I wonder how I can fetch one of this drawables programmatically or set is as background.
I thought about something like:
ContextCompat.getDrawable(context, R.drawable.icon)
Is this even possible?
Okay, I managed it myself. Thanks for @Budius for pointing me in the right direction.
The Answers lays in VectorDrawable#create()
Resources resources = context.getResources(Resources, int, Theme);
Theme theme = context.getTheme();
Drawable drawable = VectorDrawableCompat.create(resources, R.drawable.drawable, theme);
More input: How to use vector drawables in Android API lower 21?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With