简体   繁体   中英

Android webView clear data

I have a webView in my Android application that I load string into using loadData() method. I later want to reset the data I loaded into webView and load a URL using loadUrl() method. However, even if I later call loadUrl() with the URL that I need, I cannot reset the webView - it still shows the string I loaded previously. What should I do?

if (!text.isEmpty() && latexText.isEmpty()) {
    webView.setBackgroundColor(Color.parseColor("#EED5C9"));
    String format = "<html><body style=\"text-align:justify\"> %s </body></Html>";
    String data = getString(R.string.invalidChar);
    webView.loadData(String.format(format, data), "text/html", "utf-8");
    return;
}


webView.setBackgroundColor(Color.WHITE);
if (android.os.Build.VERSION.SDK_INT < 19) {
    webView.loadUrl("javascript:document.getElementById('math').innerHTML='\\\\["
        +doubleEscapeTeX(latexText)+"\\\\]';");
    webView.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
} else {
    webView.evaluateJavascript("javascript:document.getElementById('math').innerHTML='\\\\["
        +doubleEscapeTeX(latexText)+"\\\\]';", null);
    webView.evaluateJavascript("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);", null);
}

use:

webview.clearView();

it will clear the view from webview.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM