本文翻译自:How to make a background 20% transparent on Android
我如何使Textview
的背景大约20%透明(不完全透明),背景中是否有颜色(即白色)?
#1楼
参考:https://stackoom.com/question/lLzd/如何在Android上使背景-透明
#2楼
Use a color with an alpha value like #33------
, and set it as background of your editText using the XML attribute android:background=" "
. 使用具有#33------
这样的alpha值的颜色,并使用XML属性android:background=" "
将其设置为editText的android:background=" "
。
- 0% (transparent) -> #00 in hex 0%(透明)->#00(十六进制)
- 20% -> #33 20%->#33
- 50% -> #80 50%->#80
- 75% -> #C0 75%->#C0
- 100% (opaque) -> #FF 100%(不透明)-> #FF
255 * 0.2 = 51 → in hex 33 255 * 0.2 = 51→十六进制33
#3楼
Make the color have 80% in the alpha channel. 使颜色在Alpha通道中占80%。 For example, for red use #CCFF0000
: 例如,对于红色,请使用#CCFF0000
:
<TextView
...
android:background="#CCFF0000" />
In the example, CC
is the hexadecimal number for 255 * 0.8 = 204
. 在示例中, CC
是255 * 0.8 = 204
的十六进制数。 Note that the first two hexadecimal digits are for the alpha channel. 请注意,前两个十六进制数字用于alpha通道。 The format