How to load html string in a webview?

前端 未结 4 694
既然无缘
既然无缘 2020-12-07 22:25

i have a html string containing this:

    
    
      
            


        
相关标签:
4条回答
  • 2020-12-07 22:36

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

    wv.loadData(yourData, "text/html", "UTF-8");
    

    You can check this example

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

    [Edit 1]

    You should add -- \ -- before -- " -- for example --> name=\"spanish press\"

    below string worked for me

    String webData =  "<!DOCTYPE html><head> <meta http-equiv=\"Content-Type\" " +
    "content=\"text/html; charset=utf-8\"> <html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1250\">"+
     "<meta name=\"spanish press\" content=\"spain, spanish newspaper, news,economy,politics,sports\"><title></title></head><body id=\"body\">"+
    "<script src=\"http://www.myscript.com/a\"></script>şlkasşldkasşdksaşdkaşskdşk</body></html>";
    
    0 讨论(0)
  • 2020-12-07 22:37

    read from assets html file

    ViewGroup webGroup;
      String content = readContent("content/ganji.html");
    
            final WebView webView = new WebView(this);
            webView.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null);
    
            webGroup.addView(webView);
    
    0 讨论(0)
  • 2020-12-07 22:37

    You also can try out this

       final WebView webView = new WebView(this);
                webView.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null);
    
    0 讨论(0)
  • 2020-12-07 22:55

    I had the same requirement and I have done this in following way.You also can try out this..

    Use loadData method

    web.loadData("<p style='text-align:center'><img class='aligncenter size-full wp-image-1607' title='' src="+movImage+" alt='' width='240px' height='180px' /></p><p><center><U><H2>"+movName+"("+movYear+")</H2></U></center></p><p><strong>Director : </strong>"+movDirector+"</p><p><strong>Producer : </strong>"+movProducer+"</p><p><strong>Character : </strong>"+movActedAs+"</p><p><strong>Summary : </strong>"+movAnecdotes+"</p><p><strong>Synopsis : </strong>"+movSynopsis+"</p>\n","text/html", "UTF-8");

    movDirector movProducer like all are my string variable.

    In short i retain custom styling for my url.

    0 讨论(0)
提交回复
热议问题