Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Color; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import java.util.Random; public class Main { private static Random mRandom = new Random(); public static Drawable createRandomColorShapeDrawable() { GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setCornerRadius(5); drawable.setColor(createRandomColor()); return drawable; } public static int createRandomColor() { int r = 50 + mRandom.nextInt(150); int g = 50 + mRandom.nextInt(150); int b = 50 + mRandom.nextInt(150); return Color.rgb(r, g, b); } }