Minas
Minas

Reputation: 1422

How can I apply a css style to the "remote html" inside WebView after html is loaded

Let's say I want to open Google's homepage inside a WebView with a custom css.

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.google.com");

How can I change the background color to black after page is fully loaded?

Upvotes: 1

Views: 1015

Answers (1)

Reuben L.
Reuben L.

Reputation: 2859

Using Javascript injection, you can load a page and change the class styles by reloading it with a custom Javascript. For example:

view.loadUrl("your.website.com");
view.loadUrl("javascript:document.getElementsByClassName('navbar')[0].style.backgroundColor='black';");

Upvotes: 4

Related Questions