Skip to content Skip to sidebar Skip to footer

Android Webview Setbackground() Doesn't Work

I have a web view on a picture and I want when I click on a button to change the background of the webview to transparent... To do so I use webView.setBackgroundColor(Color.TRANSPA

Solution 1:

   WebView.setBackgroundColor(0);
   WebView.setBackgroundResource(Color.TRANSPARENT);

Update:: be sure to have Javascript enabled!

Solution 2:

I can confirm that the following solution works on every droid I tested (2.1, 2.3, 3.2, 4.0.3, 4.0.4, 4.1.1, 4.1.2):

webview.loadDataWithBaseURL(null, "<html><body background=\"#00000000\" link=\"white\"><font color=\"white\">" + content + "</font></body</html>", "text/html", "UTF-8", null);
webview.setBackgroundColor(0x00000000);
if (Build.VERSION.SDK_INT >= 11) // Android v3.0+try {
  Method method = View.class.getMethod("setLayerType", int.class, Paint.class);
  method.invoke(webview, 1, new Paint()); // 1 = LAYER_TYPE_SOFTWARE (API11)
 } catch (Exception e) {
}

Solution 3:

Post a Comment for "Android Webview Setbackground() Doesn't Work"