我正在尝试在 Android API 级别 21 之前为图像着色。我已成功使用以下方法着色项目:
<android:tint="@color/red"/>
但是,我似乎无法通过 ImageView 上的代码弄清楚如何做到这一点:
Drawable iconDrawable = this.mContext.getResources().getDrawable(R.drawable.somedrawable);
DrawableCompat.setTint(iconDrawable, this.mContext.getResources().getColor(R.color.red));
imageView.setImageDrawable(iconDrawable);
我试过设置 TintMode 但这似乎没有什么不同。我是否错误地使用了 v4 兼容类 DrawableCompat?