我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?

我试过了:

mImageview.setBackgroundResource(R.color.trans);

其中trans→<color name="trans">#00000000 </color>。


当前回答

试试这段代码:)

它是一个完全透明的六边形代码-“#00000000”

其他回答

在xml中

@android:color/transparent

在代码中

mComponentName.setBackgroundResource(android.R.color.transparent)

Android已经内置了一个透明的:R.color.transparent。http://developer.android.com/reference/android/R.color.html#transparent

但是我认为你可能想要使你放在WebView中的图像的背景透明,例如,使用透明的PNG,而不是ImageView背景。如果实际的图像不是完全透明的,那么ImageView背景就不能通过它被看到。

我遇到的另一个工作选项是设置android:background="@null"

试试这段代码:)

它是一个完全透明的六边形代码-“#00000000”

在XML中设置背景属性为任意颜色,白色(#FFFFFF)阴影或黑色(#000000)阴影。如果你想要透明,只需在实际的哈希码前加上80:

#80000000

这将改变任何颜色,你想要一个透明的。:)