What I need to do is an application that when you click on the screen it will just show random colours on the screen; press the screen again and you will get other random colours (colours that are not only Red, Blue, Green).
Asked
Active
Viewed 173 times
0
-
1http://stackoverflow.com/questions/5280367/android-generate-random-color-on-click – Matthew Mcveigh Mar 26 '14 at 17:38
1 Answers
2
If you need only bright, saturated colors, use Color.HSVToColor()
instead of setting R, G and B components directrly:
float[] hsvColor = {0, 1, 1};
// randomly generate only hue component,
// leaving saturation and brightness maximum possible
hsvColor[0] = new Random().nextFloat() * 360;
view.setBackgroundColor(Color.HSVToColor(hsvColor));

Alex Salauyou
- 14,185
- 5
- 45
- 67