开发者

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.TRANSPARE开发者_如何学CNT);

When I press the button my webview doesn't change it's color.. I have to write something in it to change it's color after I press the button..

Does somebody knows how to fix this?

Thank you!


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

Update:: be sure to have Javascript enabled!


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) {
}


You can use the WebView.setBackgroundColor(#00000000); It worked for me once. You can take help of this link Click HERE

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜