how to convert color opacity or trasform rgb

RGB and ARGB

  • RGB is a color model. In RGB red, green and blue light are added together in various combinations to reproduce a wide spectrum of colors
  • RGB(#RRGGBB) and ARGB(#AARRGGBB) values represent as hexadecimal values
  • In RGB you have two digits for every color (red, green, blue), in ARGB you have two additional digits for the alpha channel
  • Alpha channel represents the transparency value
  • Android use ARGB hex values to represent colors

ARGB representation(#AARRGGBB)

AA - Alpha component [0..255] of the color
RR - Red component [0..255] of the color
GG - Green component [0..255] of the color
BB - Blue component [0..255] of the color
See the Android Color resource documentation for reference.
Basically you have the option to set the transparency (opacity) and the color using android:background.
The hex value that you set it to is composed of 3 to 4 parts:
  • Alpha (opacity), i'll refer to that as aa
  • Red, i'll refer to it as rr
  • Green, i'll refer to it as gg
  • Blue, i'll refer to it as bb
Without an alpha (transparency) value:
android:background="#rrggbb"
With an alpha (transparency) value:
android:background="#aarrggbb"
The alpha value for full transparency is 00 and the alpha value for no transparency is FF
You can experiment with values in between those.

شارك الموضوع

إقرأ أيضًا