Check this to decide if white should be used on this color - Android Graphics

Android examples for Graphics:Color

Description

Check this to decide if white should be used on this color

Demo Code


//package com.java2s;

import android.graphics.Color;

public class Main {
    /**/* w ww  .j a  v  a2s.c  o m*/
     * Check this to decide if white should be used on this color
     * @param backgroundColor
     * @return {@code true} if the color is dark
     */
    public static boolean isBackgroundColorDark(int backgroundColor) {
        double darkness = 1 - (0.299 * Color.red(backgroundColor) + 0.587
                * Color.green(backgroundColor) + 0.114 * Color
                .blue(backgroundColor)) / 255;
        return darkness >= 0.4;
    }
}

Related Tutorials