mud*_*dit 309 android android-widget
我正在使用Web视图,我在其中添加图像视图.如何将此图像视图的背景设置为透明?
我试过这个:
mImageview.setBackgroundResource(R.color.trans);
Run Code Online (Sandbox Code Playgroud)
哪里trans→ <color name="trans">#00000000 </color>.
Har*_*had 543
在您的XML中,将Background属性设置为任何颜色,White(#FFFFFF)阴影或Black(#000000)阴影.如果你想要透明度,只需在实际哈希码之前加80:
#80000000
Run Code Online (Sandbox Code Playgroud)
这将改变你想要的任何颜色透明的.. :)
Chi*_*tel 542
您可以通过在XML中添加此代码来设置任何布局,任何视图或任何组件的透明背景:
android:background="@android:color/transparent"
Run Code Online (Sandbox Code Playgroud)
Aar*_*ron 173
除了哈尔沙德提到的:
两个十六进制字符可以附加到任何十六进制颜色代码.8位十六进制颜色代码中的前两个字符表示其在Android中的不透明度.
两个十六进制字符的范围为00到FF.例如,
这样,您可以将任何颜色更改为任何透明度级别.
要从百分比中查找十六进制前缀:
将百分比数除以100并乘以255得到小数值.在这里将十进制转换为十六进制.
例如,对于50%,50/100*255 = 127.使用该链接我们得到十六进制值7F.
Xar*_*mer 138
如果要添加20%或30%的透明度,则应该在十六进制代码中预先添加两个字符,例如CC.
android:background="#CCFF0088" 在XML中
其中CC是alpha值,FF是红色因子,00是绿色因子,88是蓝色因子.
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
Run Code Online (Sandbox Code Playgroud)
您还可以通过编程方式设置不透明度:
yourView.getBackground().setAlpha(127);
Run Code Online (Sandbox Code Playgroud)
将不透明度设置为0(完全透明)到255(完全不透明).127.5正好是50%.
您可以使用给定的公式创建任何级别的透明度.如果你想要半透明:
16 |128 Where 128 is the half of 256.
|8 -0 So it means 80 is half transparent.
Run Code Online (Sandbox Code Playgroud)
透明度为25%:
16 |64 Where 64 is the quarter of 256.
|4 -0 So it means 40 is quarter transparent.
Run Code Online (Sandbox Code Playgroud)
Nar*_*iya 37
使用以下代码为黑色:
<color name="black">#000000</color>
Run Code Online (Sandbox Code Playgroud)
现在,如果您想使用不透明度,那么您可以使用以下代码:
<color name="black">#99000000</color>
Run Code Online (Sandbox Code Playgroud)
以下是不透明度代码:
100% - FF
95% - F2
90% - E6
85% - D9
80% - CC
75% - 高炉
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
Int*_*ons 23
Android内置了一个透明的:R.color.transparent.http://developer.android.com/reference/android/R.color.html#transparent
但我认为您可能希望将放置到WebView中的图像的背景透明化,例如,使用透明的PNG,而不是ImageView背景.如果实际图像根本没有透视,则无法通过它看到ImageView背景.
Fel*_*los 16
如果您想在代码中使用它,只需:
mComponentName.setBackgroundColor(Color.parseColor("#80000000"));
Run Code Online (Sandbox Code Playgroud)
For*_*ran 13
在 XML 中
@android:color/transparent
Run Code Online (Sandbox Code Playgroud)
在代码中
mComponentName.setBackgroundResource(android.R.color.transparent)
Run Code Online (Sandbox Code Playgroud)
或者,作为备用,使用以下代码解析资源ID:
mComponentName.setBackgroundColor(getResources().getColor(android.R.color.transparent));
Run Code Online (Sandbox Code Playgroud)
在您的XML文件中,设置属性“ Alpha”
如
android:alpha="0.0" // for transparent
android:alpha="1.0" // for opaque
Run Code Online (Sandbox Code Playgroud)
您可以使用介于十进制的0.0到1.0之间的任何值来应用所需的透明度。例如,0.5透明度是禁用组件的理想选择
使用以下内容以实现完全透明:
#00000000
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 #80000000 时,我得到了一个我不想要的黑色透明覆盖层。尝试改变前两位数字;它控制透明度,比如
#00000000
#10000000
#20000000
#30000000
Run Code Online (Sandbox Code Playgroud)
一种更简单的方法:
mComponentName.setBackgroundResource(android.R.color.transparent);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
668538 次 |
| 最近记录: |