我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
当前回答
使用以下方法实现完全透明:
#00000000
当我尝试使用#80000000时,我得到了一个我不想要的黑色透明覆盖。试着改变前两位数字;它控制着透明度,就像
#00000000
#10000000
#20000000
#30000000
其他回答
或者,作为替代,用下面的代码解析资源ID:
mComponentName.setBackgroundColor(getResources().getColor(android.R.color.transparent));
对于那些仍然面临这个问题的人,你可以试试这个 element.getBackground () .setAlpha (0);
尝试使用下面的代码。它将帮助你完全或更多。
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:这一行代码是为你的背景风格,就像一些特殊的或不同的东西为你的目的。你也可以用这个。
还有一个更简单的方法:
mComponentName.setBackgroundResource(android.R.color.transparent);
试试这段代码:)
它是一个完全透明的六边形代码-“#00000000”