OGeek|极客世界-中国程序员成长平台

标题: android - 如何在android中以编程方式为 ImageView 设置色调? [打印本页]

作者: 菜鸟教程小白    时间: 2022-8-1 01:20
标题: android - 如何在android中以编程方式为 ImageView 设置色调?

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

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

但它并没有改变...



Best Answer-推荐答案


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

您可以通过以下方式在代码中轻松更改色调: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 - 如何在android中以编程方式为 ImageView 设置色调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20121938/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4