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.

1

2 Answers 2

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); 
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.