我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
当前回答
ImageView.setBackground(R.drawable.my_background);
ImageView.setBackgroundResource(R.color.colorPrimary);
ImageView.getImageAlpha();
ImageView.setAlpha(125); // transparency
其他回答
如果你使用一个可绘制的XML图像,你可以使它透明如下图所示,或者你可以使用一个颜色代码:
<color name="black">#99000000</color>
对于那些仍然面临这个问题的人,你可以试试这个 element.getBackground () .setAlpha (0);
试试这段代码:)
它是一个完全透明的六边形代码-“#00000000”
我遇到的另一个工作选项是设置android:background="@null"
在XML文件中,设置属性“Alpha”
如
android:alpha="0.0" // for transparent
android:alpha="1.0" // for opaque
您可以给出十进制的0.0到1.0之间的任何值来应用所需的透明度。例如,0.5透明度对于禁用组件是理想的