我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
当前回答
将百分比转换为十六进制使用任何在线工具&而不是简单地添加在前面的颜色值
例如:使用https://www.joshuamiron.com/percent-to-hex-converter
80%的不透明度
<color name="opaque_80_percent">#CC000000</color>
其他回答
如果你想在代码中使用它,只需:
mComponentName.setBackgroundColor(Color.parseColor("#80000000"));
还有一个更简单的方法:
mComponentName.setBackgroundResource(android.R.color.transparent);
使用RelativeLayout,其中有2个imageViews。并在顶部imageView上设置透明代码。
透明度代码:
<solid android:color="@color/white"/>
<gradient android:startColor="#40000000" android:endColor="#FFFFFFFF" android:angle="270"/>
Android已经内置了一个透明的:R.color.transparent。http://developer.android.com/reference/android/R.color.html#transparent
但是我认为你可能想要使你放在WebView中的图像的背景透明,例如,使用透明的PNG,而不是ImageView背景。如果实际的图像不是完全透明的,那么ImageView背景就不能通过它被看到。
在xml中
@android:color/transparent
在代码中
mComponentName.setBackgroundResource(android.R.color.transparent)