I\'m experimenting with Drawable backgrounds and have had no problems so far.
I\'m now trying to change the gradient background color at runtime.
Unfortunate
Try my code below:
int[] colors = new int[2];
colors[0] = getRandomColor();
colors[1] = getRandomColor();
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM, colors);
gd.setGradientType(GradientDrawable.RADIAL_GRADIENT);
gd.setGradientRadius(300f);
gd.setCornerRadius(0f);
YourView.setBackground(gd);
Method for generating random color:
public static int getRandomColor(){
Random rnd = new Random();
return Color.argb(255, rnd.nextInt(256), rnd.nextInt(56), rnd.nextInt(256));
}