Set transparent background of an imageview on Android


Question

I am using a web view in which I am adding an image view. How can I set the background of this image view to transparent?

I have tried this:

mImageview.setBackgroundResource(R.color.trans);

Where trans<color name="trans">#00000000 </color>.

1
301
4/28/2017 9:26:14 PM

Accepted Answer

In your XML set the Background attribute to any colour, White(#FFFFFF) shade or Black(#000000) shade. If you want transparency, just put 80 before the actual hash code:

#80000000

This will change any colour you want to a transparent one.. :)

531
10/23/2018 7:20:35 AM

You can set the background transparent of any layout, any view, or any component by adding this code in XML:

android:background="@android:color/transparent" 

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon