0

I need to change the background color of the body tag in some Html that gets loaded into a webview. I have already tried the answer located here. Here is the relevant code I have in onPageFinished():

String command = "javascript:document.body.style.background = \"transparent\";";
webView.loadUrl(command);

My WebView just ends up ditching the old Html that was originally loaded and displays "transparent" instead of changing the color like I want.

Community
  • 1
  • 1
Christopher Perry
  • 38,891
  • 43
  • 145
  • 187
  • here is another location about similar problem. u may have a look: http://stackoverflow.com/questions/10867503/change-background-image-in-body – Umit Kaya Jun 13 '14 at 03:12

2 Answers2

3

Changing the javascript to this is what works:

String javascript = "javascript:(function() { document.body.style.background='transparent'; })();";

if on KitKat+ you can do:

String javascript = "(function() { document.body.style.background='transparent'; })();";
webview.evaluateJavascript(javascript, null);
Christopher Perry
  • 38,891
  • 43
  • 145
  • 187
0

call-a-function-after-complete-page-load

you can do this in javascript code, there is not need to do this in the android java code.

Community
  • 1
  • 1
John Chen
  • 304
  • 3
  • 8