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

Viewed 80786

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?

6 Answers

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)

Related