generate Random Color and return int value - Android Graphics

Android examples for Graphics:Color Value

Description

generate Random Color and return int value

Demo Code


//package com.java2s;
import android.graphics.Color;

public class Main {

    public static int generateRandomColor() {

        long black = Long.parseLong("ff000000", 16);

        long white = Long.parseLong("ffffffff", 16);
        long colorLong = (long) (Math.random() * (black - white + 1) + white);
        String colorhex = "#" + Long.toHexString(colorLong);
        return Color.parseColor(colorhex);
    }/*from www  . java 2  s . com*/
}

Related Tutorials