Reputation: 32891
I sometimes have seen in examples where the coloring in Android is done as #FF191919. I mean an eight-digit hex number. But it should only be a six-digit number. How are they related?
If I want to convert a six-digit number to a eight-digit number, how can I do it? I mean convert #424242 to a eight-digit number coloring? What are the the details?
Upvotes: 95
Views: 86424
Reputation: 521
Eight-digit hex notation works the same as the six-digit notation, in that you provide a six-digit hexadecimal value, prefixed with a hash (#) symbol.
The difference is, eight-digit notation, as the name suggests, adds two more digits. These two digits represent the alpha channel of the color.
The alpha channel is represented by the last two digits.
This last pair of digits are interpreted as a hexadecimal number (just like the other digits). A value of 00
represents a fully transparent color, and a value of FF
represents a fully opaque color.
So for a fully opaque color do this : Color(0xFF<your-6digit-code>)
For example, if you have a 6 digit code: E64526
Now convert it to an 8 digit code with: Color(0xFFE64526)
Upvotes: 0
Reputation: 101
An eight-digit Android hexadecimal value is called an ARGB. ARGB values are typically expressed using eight hexadecimal digits, with each pair of the hexadecimal digits representing the values of the alpha, red, green and blue channel, respectively. For example, 80FFFF00 represents 50.2% opaque (non-premultiplied) yellow.
The 80 hexadecimal value, which is 128 in decimal, represents a 50.2% alpha value because 128 is approximately 50.2% of the maximum value of 255 (FF hexadecimal); to continue to decipher the 80FFFF00 value, the first FF represents the maximum value red can have; the second FF is like the previous, but for green; the final 00 represents the minimum value blue can have (effectively – no blue).
Consequently red + green yields yellow. In cases where the alpha is not used, this can be shortened to six digits, RRGGBB, and this is why it was chosen to put the alpha in the top bits. Depending on the context, a 0x or a number sign, #, is put before the hexadecimal digits.
Upvotes: 10
Reputation: 37915
The extra two digits are used to define the colors' transparency, or alpha channel.
Android uses the ARGB format (or AARRGGBB as you use in your example).
For more (Android-specific) information, take a look at the Color documentation.
Upvotes: 114
Reputation: 1484
The eight-digit hexadecimal value is an ARGB color. It is the same as the usual RGB, but it provides an extra alpha channel.
#RRGGBB in RGB is the same as #00RRGGBB
in ARGB. Also take a look at Color.argb.
Upvotes: 16
Reputation: 30855
The eight-digit color is defined with an alpha level.
Let’s extract all. We define the hexadecimal color as six value pairs of RGB two digits per pair.
Now if you want to set the alpha level of that then it is defined with the eight digits as ARGB.
So now the first two digit values define the alpha and the rest are for the RGB.
Upvotes: 8
Reputation: 15570
The first two characters represent the alpha (transparency) value, where FF is fully visible. This is known as ARGB.
Upvotes: 48