Transparent Backgrounds on Android Views

A frequent question encountered when using WebView inside of an Android app is “how do I make the background transparent, rather than the default white color?

This is ridiculously easy:

WebView myWebView = new WebView(this);
myWebView.setBackgroundColor(0);


Happy Coding.

About these ads

2 Comments

Filed under Android, Development

2 Responses to Transparent Backgrounds on Android Views

  1. Josh

    Yeah, this works until you use JavaScript to show/hide a div, or do something else dynamic. The WebView doesn’t clear it’s canvas before drawing to it again, so you get terrible artifacts.

    • hailrok

      I’m facing exactly the problem you described :(
      Did you find any workarounds for WebView with transparent background not redrawing correctly after JavaScript manipulations?

      Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s