我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
当前回答
还有一个更简单的方法:
mComponentName.setBackgroundResource(android.R.color.transparent);
其他回答
在XML文件中,设置属性“Alpha”
如
android:alpha="0.0" // for transparent
android:alpha="1.0" // for opaque
您可以给出十进制的0.0到1.0之间的任何值来应用所需的透明度。例如,0.5透明度对于禁用组件是理想的
在XML中设置背景属性为任意颜色,白色(#FFFFFF)阴影或黑色(#000000)阴影。如果你想要透明,只需在实际的哈希码前加上80:
#80000000
这将改变任何颜色,你想要一个透明的。:)
对于那些仍然面临这个问题的人,你可以试试这个 element.getBackground () .setAlpha (0);
在xml中
@android:color/transparent
在代码中
mComponentName.setBackgroundResource(android.R.color.transparent)
如果你想在代码中使用它,只需:
mComponentName.setBackgroundColor(Color.parseColor("#80000000"));