If we enable chrome://flags/#enable-force-dark flag in chrome browser on android then web page becomes dark.
I want to achieve similar thing (i.e. dark web ui) in android webview.
Currently I am using following code:
private void injectCSS() {
String code = "javascript:(function() {" +
"var node = document.createElement('style');"+
"node.type = 'text/css';"+
" node.innerHTML = 'body, label,th,p,a, td, tr,li,ul,span,table,h1,h2,h3,h4,h5,h6,h7,div,small {"+
" color: #deFFFFFF;"+
"background-color: #232323;"+
" } ';"+
" document.head.appendChild(node);})();";
webView.evaluateJavascript(code,null);
}
I run this code in:
@Override
public void onProgressChanged(WebView view, final int
newProgress) {
super.onProgressChanged(view, newProgress);
injectCSS();
}
@Override
public void onPageStarted(final WebView view, String url,
Bitmap favicon) {
injectCSS();
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, final String url)
{
injectCSS();
super.onPageFinished(view, url);
}
Now I get near about same dark web pages like chrome. But I want to improve this code because it has some issues like anchor links not gets displayed properly. Suggest any better technique (if available)