Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

android - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...