0

I'm generating random RGB values

int r = rand.nextInt(255); // [0,255]
int g = rand.nextInt(255); // [0,255]
int b = rand.nextInt(255); // [0,255]

How can I convert these integers into another value (maybe int or hex?) so I can set a view's background color like so

int color = getColor(r,g,b);
myView.setBackgroundColor(color);

What might the getColor() method looks like?

the_prole
  • 8,275
  • 16
  • 78
  • 163

1 Answers1

0

you'll need to use the static method Color.rgb.

int color = Color.rgb(r,g,b);

Color.rgb

Return a color-int from red, green, blue components. The alpha component is implicitly 255 (fully opaque). These component values should be [0..255], but there is no range check performed, so if they are out of range, the returned color is undefined.

Ousmane D.
  • 54,915
  • 8
  • 91
  • 126