Jared Jared - 11 months ago 51
Android Question

Android: Generate random color on click?

I have an

, in which I am programmaticly creating drawables and presenting them to the user. My goal is to click on said
and change the drawable's color.

How would I go about the random color changing bit? I am currently tinkering with
and a few other things, but I can't seem to get it to work!

Answer Source
Random rnd = new Random();
paint.setARGB(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));


Random rnd = new Random(); 
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));   

Though in your case it seems that you want to create a new drawable and assign it to your view. What is actually the drawable in your case? Is it an image, shape, fill...