所以,我想对 Android 中的图像应用滤镜,该图像全是绿色,但具有不同的色调,我想将其设为红色。现在我正在使用这段代码:
Drawable ballon = ContextCompat.getDrawable(context, R.drawable.msg_out);
ballon.setColorFilter(new
PorterDuffColorFilter(context.getResources().getColor(R.color.redLightClose), PorterDuff.Mode.MULTIPLY));
view.setBackgroundDrawable(ballon);
但结果我得到了两种颜色的棕色混合......我应该使用另一种过滤器吗?如果是这样,您会推荐一个女巫。
最佳答案
我使用 Tint 代替,它完成了工作。
Drawable iconDrawable = ContextCompat.getDrawable(context, R.drawable.msg_out);
DrawableCompat.setTint(iconDrawable, context.getResources().getColor(R.color.primary));
setBackgroundViewCompat(text, iconDrawable);
关于java - Android滤镜,改变可绘制颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31817773/