我正在使用一个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

其他回答

试试这个:

#aa000000

对于透明度000000 =黑色,您可以更改这六个数字为您想要的颜色。

如果你想在代码中使用它,只需:

mComponentName.setBackgroundColor(Color.parseColor("#80000000"));

尝试使用下面的代码。它将帮助你完全或更多。

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:这一行代码是为你的背景风格,就像一些特殊的或不同的东西为你的目的。你也可以用这个。

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

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

或者,作为替代,用下面的代码解析资源ID:

  mComponentName.setBackgroundColor(getResources().getColor(android.R.color.transparent));