How to pass html string to webview on android

后端 未结 4 1002
无人共我
无人共我 2020-11-30 19:13

Hi I am parsing xml and then loading it to web view, after parsing I am creating four strings so that I could append all string to one view. I am able to get two views on th

相关标签:
4条回答
  • 2020-11-30 19:24

    To load your data in WebView. Call loadData() method of WebView

    webView.loadData(yourData, "text/html; charset=utf-8", "UTF-8");
    

    You can check this example

    http://developer.android.com/reference/android/webkit/WebView.html

    0 讨论(0)
  • 2020-11-30 19:37

    Passing null would be better. The full codes is like:

    WebView wv = (WebView)this.findViewById(R.id.myWebView);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.loadDataWithBaseURL(null, "<html>...</html>", "text/html", "utf-8", null);
    
    0 讨论(0)
  • 2020-11-30 19:44

    I was using some buttons with some events, converted image file coming from server. Loading normal data wasn't working for me, converting into Base64 working just fine.

    String unencodedHtml ="<html><body>'%28' is the code for '('</body></html>";
    tring encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(), Base64.NO_PADDING);
    webView.loadData(encodedHtml, "text/html", "base64");
    

    Find details on WebView

    0 讨论(0)
  • 2020-11-30 19:45

    i have successfully done by below line

     //data == html data which you want to load
     String data = "Your data which you want to load";
    
     WebView webview = (WebView)this.findViewById(R.id.webview);
     webview.getSettings().setJavaScriptEnabled(true);
     webview.loadData(data, "text/html; charset=utf-8", "UTF-8");
    

    Or You can try

     webview.loadDataWithBaseURL(null, data, "text/html", "utf-8", null);
    
    0 讨论(0)
提交回复
热议问题