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