问题描述
我对使用支持库23.2.0中引入的app:srcCompat="@drawable/icon"
属性将矢量可绘制对象设置为布局的新可能性感到非常兴奋.
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.
我想到了类似的东西:ContextCompat.getDrawable(context, R.drawable.icon)
I thought about something like:ContextCompat.getDrawable(context, R.drawable.icon)
这有可能吗?
推荐答案
好的,我自己进行了管理.感谢@Budius为我指出正确的方向.
Okay, I managed it myself. Thanks for @Budius for pointing me in the right direction.
Resources resources = context.getResources(Resources, int, Theme);
Theme theme = context.getTheme();
Drawable drawable = VectorDrawableCompat.create(resources, R.drawable.drawable, theme);
更多输入:如何在Android API较低版本21中使用矢量可绘制对象?/a>
More input:How to use vector drawables in Android API lower 21?
这篇关于23.2.0将可绘制的矢量设置为4.X中的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!