Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do int color codes in android work?

I have the following problem:

I have a list view, I want to assign a gradient color to item separator ( Divider) of this list view. I am using the following code:

    list = (ListView) findViewById(R.id.list);
    int[] colors = { 0, 0xffffff00, 0 }; 
    list.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    list.setDividerHeight(4);

I looked up the color code (0xffffff00) from: http://developer.android.com/reference/android/graphics/Color.html

PROBLEM:

However this color is Yellow, what I want is golden. I am also interested to know how this works, I mean how can I define the color of my choice, so far I tried to understand from the developer site but it is not much clear.

like image 923
user2613996 Avatar asked Jul 27 '13 10:07

user2613996


2 Answers

that you wrote is the hex notation. You can think about a color as composed of 4 components. ARGB. In your example you have 0xffffff00. The first ff is the alpha component, the second ff is the red component, the third ff is green component the fourth 00 is the blue component. Change those hexadecimal values you can get your colors.

Use

int color = Color.argb(255, 255, 175, 64);

or use an iteger to hex converter

like image 96
Blackbelt Avatar answered Nov 01 '22 02:11

Blackbelt


For gold you need a yellow that's more red than green, so try 0xffffc000. In decimal that would be red 255 green 192 blue 0. To really get a hold of how the RGB system works spend a while playing with the values, I don't think it's possible to get a deep understanding just by reading about it.

like image 27
Joni Avatar answered Nov 01 '22 03:11

Joni