我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?
我试过了:
mImageview.setBackgroundResource(R.color.trans);
其中trans→<color name="trans">#00000000 </color>。
当前回答
还有一个更简单的方法:
mComponentName.setBackgroundResource(android.R.color.transparent);
其他回答
试试这个:
#aa000000
对于透明度000000 =黑色,您可以更改这六个数字为您想要的颜色。
对于那些仍然面临这个问题的人,你可以试试这个 element.getBackground () .setAlpha (0);
我遇到的另一个工作选项是设置android:background="@null"
黑色使用下面的代码:
<color name="black">#000000</color>
现在如果你想使用不透明度,那么你可以使用下面的代码:
<color name="black">#99000000</color>
下面是不透明代码:
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00
ImageView.setBackground(R.drawable.my_background);
ImageView.setBackgroundResource(R.color.colorPrimary);
ImageView.getImageAlpha();
ImageView.setAlpha(125); // transparency