我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
当前回答
试试这个:
#aa000000
对于透明度000000 =黑色,您可以更改这六个数字为您想要的颜色。
其他回答
ImageView.setBackground(R.drawable.my_background);
ImageView.setBackgroundResource(R.color.colorPrimary);
ImageView.getImageAlpha();
ImageView.setAlpha(125); // transparency
或者,作为替代,用下面的代码解析资源ID:
mComponentName.setBackgroundColor(getResources().getColor(android.R.color.transparent));
如果你想在代码中使用它,只需:
mComponentName.setBackgroundColor(Color.parseColor("#80000000"));
已经有一个预定义的常量。使用Color.TRANSPARENT。
在Android Studio中,使用内置工具调整颜色和不透明度非常简单: