我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
当前回答
在XML文件中,设置属性“Alpha”
如
android:alpha="0.0" // for transparent
android:alpha="1.0" // for opaque
您可以给出十进制的0.0到1.0之间的任何值来应用所需的透明度。例如,0.5透明度对于禁用组件是理想的
其他回答
ImageView.setBackground(R.drawable.my_background);
ImageView.setBackgroundResource(R.color.colorPrimary);
ImageView.getImageAlpha();
ImageView.setAlpha(125); // transparency
除了哈沙德提到的:
两个十六进制字符可以追加到任何十六进制颜色代码。8位十六进制颜色代码中的前两个字符表示其在Android中的不透明度。
两个十六进制字符,取值范围为00 ~ FF。例如,
普通不透明黑六角- "#000000" 全透明- "#00000000" 完全不透明- "#FF000000" 50%透明- "#7F000000"
这样你就可以改变任何颜色到任何级别的透明度。
从百分比中找到十六进制前缀:
百分数除以100,再乘以255,得到小数。这里把十进制转换成十六进制。
例如,对于50%,50/100 * 255 = 127。使用该链接,我们得到了十六进制值7F。
Android:如何创建透明或不透明的背景
尝试使用下面的代码。它将帮助你完全或更多。
A .xml file designed to use this code to set background color: android:background="#000000" or android:background="#FFFFFF" Or you can set it programmatically as well. Also you can use this code programmatically: image.setBackgroundDrawable(getResources().getDrawable( R.drawable.llabackground)); Also this code for setting the background color as well programmatically: image.setBackgroundColor(Color.parseColor("#FFFFFF")); This code for the same programmatically: image.setBackgroundColor(getResources().getColor(Color.WHITE));
颜色取决于你想要使用哪种颜色的透明。主要使用白色或#FFFFFF颜色。
关于R.drawable.llabackground:这一行代码是为你的背景风格,就像一些特殊的或不同的东西为你的目的。你也可以用这个。
使用RelativeLayout,其中有2个imageViews。并在顶部imageView上设置透明代码。
透明度代码:
<solid android:color="@color/white"/>
<gradient android:startColor="#40000000" android:endColor="#FFFFFFFF" android:angle="270"/>
带有透明信息的颜色定义可以在窗体中
#AARRGGBB或#ARGB。
你也可以使用更短的值来表示完全透明: # 0000。
其他值包括:
white grey black
#FFFF #F888 #F000 - full color
#EFFF #E888 #E000
#DFFF #D888 #D000
#CFFF #C888 #C000
#BFFF #B888 #B000
#AFFF #A888 #A000
#9FFF #9888 #9000
#8FFF #8888 #8000
#7FFF #7888 #7000
#6FFF #6888 #6000
#5FFF #5888 #5000
#4FFF #4888 #4000
#3FFF #3888 #3000
#2FFF #2888 #2000
#1FFF #1888 #1000
#0FFF #0888 #0000 - full transparency