1

I want to change the background-color and the text-color from a website loaded into a WebView (to display a website with a dark theme). I know that this should be possible by injecting some javascript. I´ve read other questions of this topic and found different ways to achieve this, however they are not working for every website.

For example this code:

"javascript:document.body.style.setProperty(\"color\", \"white\");"

If I add this js to the webview, some websites change their color (e.g. https://dpreview.com) but other websites stay normal (e.g. https://golem.de). However this code works in desktop-browsers like Edge (even for https://golem.de).

I´ve also tried this code:

(function() {
var node = document.createElement('style');
document.body.appendChild(node);
window.addStyleString = function(str) {
    node.innerHTML = str;
}
}());

addStyleString('body { color: red }');

This code also works in Edge for all websites but doesnt work in webview (not even for websites where the other code worked)

Is there any way to achieve a dark-theme (white text, black background) in WebView?

Aljosha
  • 222
  • 2
  • 9

0 Answers0