How To Make A Background Transparent In Android Dialog

This one was pretty tricky because I got fooled into thinking that creating an XML file that contains shape attributes is the solution and setting the solid attribute to transparent would make an Android Dialog‘s background transparent.

This was not the case since I assigned the XML file to the background of a LinearLayout. Most of the forums I read gave this suggestion. However, the result is incorrect.

This is because the background of the Dialog is still not transparent. When I assigned the XML file as the background of the LinearLayout, it only put those attributes on the LinearLayout. Since the Dialog background is not transparent, its solid color overlapped the LinearLayout transparent background thus giving the assumption that it never worked.

To make the background of the Dialog transparent, you can do it this way:

This is my sample XML file set as a drawable background for the LinearLayout.

The solid attribute contains the value #AARRGGBB where A is alpha while RGB are the 3 colors red, green and blue. I set my alpha’s value to 90 so it would not be so transparent. You can change it according to your preference with values between 0 – 99.

Remember, if you set the alpha value to 00, then it will be the same as being invisible.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *