Java - Is it possible to inject html into a web with webView (Android)

0

I know that it is possible to inject CSS into a page (online) to modify after it finishes loading. I've already done it this way.

@Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        injectCSS();
        }



private void injectCSS() {
        try {
            InputStream inputStream = getAssets().open("newstyle.css");
            byte[] buffer = new byte[inputStream.available()];
            inputStream.read(buffer);
            inputStream.close();
            String encoded = Base64.encodeToString(buffer, Base64.NO_WRAP);
            webView.loadUrl("javascript:(function() {" +
                    "var parent = document.getElementsByTagName('head').item(0);" +
                    "var style = document.createElement('style');" +
                    "style.type = 'text/css';" +
                    "style.innerHTML = window.atob('" + encoded + "');" +
                    "parent.appendChild(style)" +
                    "})()");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

I would like to know if it is possible to do the same but with the html. example to change a button position or change texts or icons. what part of the code should I modify to load html. Thanks for your attention.

    
asked by Andres Gonzalez 22.05.2018 в 22:30
source

0 answers