親のテキストと画像の色合いをある色に設定する方法があります。今、親と前景の色合い(私が設定している色合い)が対照的に近い場合、テキストは読み込みできなくなります。2色のコントラストの差を見つける
これら2つの色の違いを確認して、どれが読みやすくなるようにするにはどうすればよいですか(明るくなるか暗くする)か?
public static void invokeContrastSafety(ViewGroup parent, int tint, boolean shouldPreserveForeground) {
Drawable background = parent.getBackground();
if (background instanceof ColorDrawable) {
if (isColorDark(((ColorDrawable) background).getColor())) {
// Parent background is dark
if (isColorDark(tint)) {
// Tint (foreground) color is also dark.
if (shouldPreserveForeground) {
// We can't modify tint color, changing background to make things readable.
} else {
// Altering foreground to make things readable
}
invokeInternal(parent, tint);
} else {
// Everything is readable. Just pass it on.
invokeInternal(parent, tint);
}
} else {
// Parent background is light
if (!isColorDark(tint)) {
if (shouldPreserveForeground) {
} else {
}
} else {
invokeInternal(parent, tint);
}
}
}
}
private static boolean isColorDark(int color){
double darkness = 1-(0.299* Color.red(color) + 0.587*Color.green(color) + 0.114*Color.blue(color))/255;
return darkness >= 0.2;
}
私の答えを参照してくださいこれはあなたを助けることを願っています。 –
[RGB色の明るさを決定する式]の可能な複製(https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color) – geza