transparency - How to make a background 20% transparent on Android -
how make background of textview
20% transparent (not transparent), there color in background (i.e. white)?
make color have 80% in alpha channel. example, red use #ccff0000
:
<textview ... android:background="#ccff0000" />
in example, cc
hexadecimal number 255 * 0.8 = 204
. note first 2 hexadecimal digits alpha channel. format #aarrggbb
, aa
alpha channel, rr
red channel, gg
green channel , bb
blue channel.
i'm assuming 20% transparent means 80% opaque. if meant other way, instead of cc
use 33
hexadecimal 255 * 0.2 = 51
.
in order calculate proper value alpha transparency value can follow procedure:
- given transparency percentage, example 20%, know opaque percentage value 80% (this
100-20=80
) - the range alpha channel 8 bits (
2^8=256
), meaning range goes 0 255. - project opaque percentage alpha range, is, multiply range (255) percentage. in example
255 * 0.8 = 204
. round nearest integer if needed. - convert value obtained in 3., in base 10, hexadecimal (base 16). can use google or calculator. using google, type "204 hexa" , give hexadecimal value. in case
0xcc
. - prepend value obtained in 4. desired color. example, red,
ff0000
, haveccff0000
.
you can take @ android documentation colors.
Comments
Post a Comment