ChatGPT解决这个技术问题 Extra ChatGPT

Hex colors in Android are sometimes eight digits. How? What is the difference between #FFFFFF and #FFFFFF00?

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?


P
Peter Mortensen

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.


Is there a good program to use that will show you the colors after typing in all 8 digits?
There are a lot: any self respecting drawing application accepts RGBA input and shows the resulting color. Or search for 'rgb color picker' or 'rgb color wheel' to find website providing this service. (Note: that the alpha digits are not really interesting as they define the transparency and do not influence the color)
Answer alone doesn't make it clear which are those extra 2 digits. first two? last two? two digits somewhere in the middle?
'extra 2 digits' suggest the are appended (so last two), but I'll update the answer to make this explicit and correct
P
Peter Mortensen

The first two characters represent the alpha (transparency) value, where FF is fully visible. This is known as ARGB.


so for example #FF000000 is the same as #000000, which is just solid black?
P
Peter Mortensen

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.


P
Peter Mortensen

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.


P
Peter Mortensen

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.

The first two digits for red.

The second two digits for green.

The third two digits for blue.

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.


S
Sharukh Rahman

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)