23.2.0 在 4.X 中将矢量可绘制对象设置为背景

23.2.0 set vector drawable as background in 4.X

我对使用 support-library 23.2.0 中引入的 app:srcCompat="@drawable/icon" 属性将矢量可绘制对象设置为布局的新可能性感到非常兴奋。

但我想知道如何以编程方式获取其中一个可绘制对象或将其设置为背景。

我想到了类似的事情: ContextCompat.getDrawable(context, R.drawable.icon)

这可能吗?

好的,我自己搞定了。感谢@Budius 为我指明了正确的方向。

答案就在VectorDrawable#create()

Resources resources = context.getResources(Resources, int, Theme);
Theme theme = context.getTheme();
Drawable drawable = VectorDrawableCompat.create(resources, R.drawable.drawable, theme);

更多输入: