我正在尝试在 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?