Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 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 Reply

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...