Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

23.2.0 set vector drawable as background in 4.X

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?

like image 273
Langusten Gustel Avatar asked Mar 10 '16 12:03

Langusten Gustel


1 Answers

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?

like image 93
Langusten Gustel Avatar answered Oct 21 '22 08:10

Langusten Gustel