3

I have a WebView based app to which I want to add a 'night-mode'. My first instinct was to just have the program render the right CSS values each time depending on whether night-mode was on or not, and it works great, but it means that the page has to be reloaded each time the mode is toggled. Is there any way I can change the css values retro-actively without having to reload the page?

1 Answer 1

3

You could inject code into your page's DOM. So you could for example have a reset stylesheet, and then inject a day or night mode class with javascript into the dom as required like this:

public class WebClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) 
    {       
        view.loadUrl("javascript:document.getElementById(id).style.property=new style");       
    }
}

HTH

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.