在 Lollipop 之前以编程方式设置矢量可绘制对象

Set vector drawable programmatically pre Lollipop

非常普遍的问题,但我找不到解决方案。 我正在以编程方式设置我的矢量。我也希望能够以编程方式更改色调。 找到了一些解决方案,例如

ImageView iv = ....
Drawable d = VectorDrawableCompat.create(getResources(), R.drawable.ic_exit_to_app_24dp, null);
d = DrawableCompat.wrap(d);
DrawableCompat.setTint(d, headerTitleColor);
iv.setImageDrawable(d);

主要问题来自

iv.setImageDrawable(d);

我发现 prelolipop 只接受设置视图的可绘制对象

iv.setImageResource(int resource)

我找不到任何使用可绘制文件进行设置的解决方案。

使用具有 setImageDrawable() 方法的 AppCompatImageView。