如何在android中以编程方式为图像视图设置色调? [英] How to set tint for an image view programmatically in android?

查看:19
本文介绍了如何在android中以编程方式为图像视图设置色调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要为图像视图设置色调...我使用它的方式如下:

Need to set tint for an image view... I am using it the following way:

imageView.setColorFilter(R.color.blue,android.graphics.PorterDuff.Mode.MULTIPLY);

但它并没有改变......

But it doesn't change...

推荐答案

更新:
@ADev 在他的回答 这里 中有更新的解决方案,但他的解决方案需要更新的支持库 - 25.4.0 或更高版本.

UPDATE:
@ADev has newer solution in his answer here, but his solution requires newer support library - 25.4.0 or above.

您可以通过以下方式在代码中轻松更改色调:

You can change the tint, quite easily in code via:

imageView.setColorFilter(Color.argb(255, 255, 255, 255));//白色色调

如果你想要颜色,那么

imageView.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.MULTIPLY);

对于矢量绘图

imageView.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.SRC_IN);

这篇关于如何在android中以编程方式为图像视图设置色调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆