Android webview append css to existing site

51 views Asked by At

I am using the webview as following

WebView webView = (WebView) this.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://m.facebook.com");

It loads the page fine. Now I am trying to add a line head section of the page before it renders in the web view. e.g.

<style>.test{color:red}</style>

is it possible to add. if yes then how??

1

There are 1 answers

0
LynAs On BEST ANSWER

this can be done using evaluateJavascript

webView.evaluateJavascript("javascript: document.getElementById('header').setAttribute('style','background-color: red;') ", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
  //in case you have some return value from your script
}
});