You can run javascript using the WebViewClient example, here .
Javascript code that changes the background color of a document .
So, all together:
When launching WebView:
WebView webview = new WebView(); webview.setWebViewClient(new WebClient()); webView.getSettings().setJavaScriptEnabled(true); webview.loadUrl("stackoverflow.com");
Your webview client:
public class WebClient extends WebViewClient { int color; public WebClient(int color) { this.color = color; } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onPageFinished(WebView view, String url) { String command = "javascript:document.body.style.background = " + color + ";"; view.loadUrl(command); } }
source share