Reinherd
Reinherd

Reputation: 5506

Set a RGBA color to a layout

I've a Layout which has a bg color customized by user. User fills 4 values. R-G-B-Alpha

But, I've seen that the method to set the color in a layout, doesnt accept 4 values. setBackgroundColor() just accepts int value.

I've searched for a java parser, from RGBA to HEX but I couldn't find any.

Do you know guys where could I find one?

Thanks.

Upvotes: 3

Views: 13451

Answers (3)

Blackbelt
Blackbelt

Reputation: 157467

int alpha = (int)(a * 255.0f);
Color.argb(alpha, r, g, b);

Upvotes: 11

yuva ツ
yuva ツ

Reputation: 3703

write color code in color.xml in values folder-

<resources>
<color name="white">#FFFFFFFF</color>
<color name="black">#FF000000</color>
<color name="red">#FFFF0000</color>
<color name="blue">#FF0000FF</color>

then in your code set layout background

LinearLayout ll=find(...);
ll.setBackgroundResource(R.color.white);

Upvotes: -4

Bishan
Bishan

Reputation: 15720

Try this one.

setBackgroundColor(Color.argb(a_int, r_int, g_int, b_int));

Upvotes: 14

Related Questions