get random color rgb value - Android Graphics

Android examples for Graphics:Color Value

Description

get random color rgb value

Demo Code


//package com.java2s;
import java.util.Random;
import android.graphics.Color;

public class Main {
    /**/*from  w  w  w . j a v a  2s.  c  o  m*/
     * get random color rgb value
     * @return rgb color int
     */
    public static int getRandomColor() {
        Random random = new Random();
        /*
         * Better limiting value.
         * if value is too small, it will appear lighter
         * if value is too large, it will appear darker
         */
        //limit within 50-199
        int red = random.nextInt(150) + 50;
        int green = random.nextInt(150) + 50;
        int blue = random.nextInt(150) + 50;
        //create a color int as per rgb and return
        return Color.rgb(red, green, blue);
    }
}

Related Tutorials