Android UI How to - Set a constant value level in HSV, in case the averaged color is too light or too dark








Question

We would like to know how to set a constant value level in HSV, in case the averaged color is too light or too dark.

Answer

// w  ww  . j a va  2  s.c o  m


import android.graphics.Color;

public class Main {

    public static int getHighlightColor(int sampleColor) {
        float[] hsvBackground = new float[3];
        Color.colorToHSV(sampleColor, hsvBackground);
        hsvBackground[2] = 0.3f; // value parameter

        return Color.HSVToColor(0xf2, hsvBackground);
    }
}