[英]How to change the color of a textView programmatically for a good contrast on Android Studio?
i'm wondering if there is a fonction that takes an Color int and return the "Opposite color "(between Black and White)我想知道是否有一个函数接受 Color int 并返回“相反的颜色”(介于黑色和白色之间)
I would use it in a recyclerView Adapter, with a background color that is customizable.我会在 recyclerView 适配器中使用它,背景颜色是可定制的。
Thank you, you devs:)谢谢你们,开发者:)
I quickly thought about creating my own function, but I would appreciate being aware of any official method:)我很快想到创建自己的 function,但如果能知道任何官方方法,我将不胜感激:)
I share with you what I've written, it's working fine.我与你分享我写的东西,它工作正常。
private int createContrastColor(int color) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
if (red > 125 && green > 125 && blue > 125){
return Color.Black;
} else {
return Color.White;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.