我试图了解颜色在Android中是如何工作的。我有这个颜色设置为我的线性布局的背景,我得到了一个灰色的背景和一些透明度:
<gradient android:startColor="#b4555555" android:endColor="#b4555555"
android:angle="270.0" />
如果我删除最后两个字符(55),我得到一个纯色,失去透明度。我试图找到一个页面,在那里我可以看到一些关于这个的解释,但我找不到。
我试图了解颜色在Android中是如何工作的。我有这个颜色设置为我的线性布局的背景,我得到了一个灰色的背景和一些透明度:
<gradient android:startColor="#b4555555" android:endColor="#b4555555"
android:angle="270.0" />
如果我删除最后两个字符(55),我得到一个纯色,失去透明度。我试图找到一个页面,在那里我可以看到一些关于这个的解释,但我找不到。
当前回答
Android使用十六进制的ARGB值,格式化为#AARRGGBB。第一对字母AA代表alpha通道。必须将十进制不透明度值转换为十六进制值。以下是步骤:
Alpha十六进制数值过程
Take your opacity as a decimal value and multiply it by 255. So, if you have a block that is 50% opaque the decimal value would be .5. For example: .5 x 255 = 127.5 The fraction won't convert to hexadecimal, so you must round your number up or down to the nearest whole number. For example: 127.5 rounds up to 128; 55.25 rounds down to 55. Enter your decimal value in a decimal-to-hexadecimal converter, like http://www.binaryhexconverter.com/decimal-to-hex-converter, and convert your values. If you only get back a single value, prefix it with a zero. For example, if you're trying to get 5% opacity and you're going through this process, you'll end up with the hexadecimal value of D. Add a zero in front of it so it appears as 0D.
这就是找到alpha通道值的方法。我冒昧地给你列了一份价值观清单。享受吧!
十六进制不透明度值
100% - ff 95% - f2 90% - e6 85% - d9 80% - cc 75% - bf 70% - b3 65% - a6 60% - 99 55% - 8c 50% - 80 45% - 73 40% - 66 35% - 59 30% - 4d 25% - 40 20% - 33 15% - 26 10% - 1a 5% - 0d 0% - 00
其他回答
十六进制代码中的颜色被写成 # aa rr gg bb #阿尔法红绿蓝
对于每一组(AA,RR,GG,BB)可能的值为: -> 00 ~ FF的十六进制格式,即十进制形式0 ~ 255
所以要改变颜色的Alpha/AA/透明度,你只需要改变十六进制字符串中的前两个十六进制字符,这是由AA组表示的
对于50% -> 255 x 0.50= 128(约/四舍五入) 和转换 128转十六进制 = 08年
所以绿色#00FF00和50% Alpha/透明度将是#0800FF00
Android使用十六进制的ARGB值,格式化为#AARRGGBB。第一对字母AA代表alpha通道。必须将十进制不透明度值转换为十六进制值。以下是步骤:
Alpha十六进制数值过程
Take your opacity as a decimal value and multiply it by 255. So, if you have a block that is 50% opaque the decimal value would be .5. For example: .5 x 255 = 127.5 The fraction won't convert to hexadecimal, so you must round your number up or down to the nearest whole number. For example: 127.5 rounds up to 128; 55.25 rounds down to 55. Enter your decimal value in a decimal-to-hexadecimal converter, like http://www.binaryhexconverter.com/decimal-to-hex-converter, and convert your values. If you only get back a single value, prefix it with a zero. For example, if you're trying to get 5% opacity and you're going through this process, you'll end up with the hexadecimal value of D. Add a zero in front of it so it appears as 0D.
这就是找到alpha通道值的方法。我冒昧地给你列了一份价值观清单。享受吧!
十六进制不透明度值
100% - ff 95% - f2 90% - e6 85% - d9 80% - cc 75% - bf 70% - b3 65% - a6 60% - 99 55% - 8c 50% - 80 45% - 73 40% - 66 35% - 59 30% - 4d 25% - 40 20% - 33 15% - 26 10% - 1a 5% - 0d 0% - 00
在新的chrome版本(可能67.0.3396.62),CSS十六进制颜色可以使用这个模型显示,
eg:
div{
background-color:#FF00FFcc;
}
Cc是不透明度,但旧chrome不支持该mod
在Android上,颜色可以指定为RGB或ARGB。
http://en.wikipedia.org/wiki/ARGB
在RGB中,每种颜色(红、绿、蓝)都有两个字符,在ARGB中,alpha通道有两个额外的字符。
如果你有8个字符,它是ARGB,前两个字符指定alpha通道。如果你去掉前面的两个字符,它只是RGB(纯色,没有alpha/透明度)。如果你想在你的Java源代码中指定一种颜色,你必须使用:
int Color.argb (int alpha, int red, int green, int blue)
alpha Alpha component [0..255] of the color
red Red component [0..255] of the color
green Green component [0..255] of the color
blue Blue component [0..255] of the color
参考:argb
8位十六进制颜色值表示ARGB (Alpha, Red, Green, Blue),而6位值仅假设100%不透明度(完全不透明)并仅定义RGB值。所以要使它完全不透明,你可以使用#FF555555,或者只是#555555。每个2位十六进制值是一个字节,表示0-255之间的值。