Search code examples
androidcolorshextransparency

Understanding colors on Android (six characters)


I am trying to understand how colors work in Android. I have this color set as the background of my LinearLayout, and I get a background gray with some transparency:

<gradient android:startColor="#b4555555" android:endColor="#b4555555"
 android:angle="270.0" />

If I remove the last two characters (55) I get a solid color, losing the transparency. I was trying to find a page where I can see some explanation about this, but I couldn't find it.


Solution

  • If you provide 6 hex digits, that means RGB (2 hex digits for each value of red, green and blue).

    If you provide 8 hex digits, it's an ARGB (2 hex digits for each value of alpha, red, green and blue respectively).

    So by removing the final 55 you're changing from A=B4, R=55, G=55, B=55 (a mostly transparent grey), to R=B4, G=55, B=55 (a fully-non-transparent dusky pinky).

    See the "Color" documentation for the supported formats.