Directly put html code in a WebView (Android)

后端 未结 3 913
悲&欢浪女
悲&欢浪女 2021-02-06 23:18

While using WebView, we usually put a URL for it:

WebView.loadUrl(myURL);

but it is possible to put HTML code directly?? So that it will be in

相关标签:
3条回答
  • 2021-02-06 23:43

    Try this code. It works for me.

    WebSettings settings = mDesc.getSettings();
    settings.setDefaultTextEncodingName("utf-8");
    mDesc.loadData(mDescText, "text/html; charset=utf-8",null);
    
    0 讨论(0)
  • 2021-02-06 23:45
     String yourhtmlpage = "<html><body>You scored <b>hello world</b> points.</body></html>";
     webview.loadDataWithBaseURL(null, yourhtmlpage, "text/html", "UTF-8", null);
    
    0 讨论(0)
  • 2021-02-06 23:55

    Check out this: http://developer.android.com/reference/android/webkit/WebView.html

     // OR, you can also load from an HTML string:
     String summary = "<html><body>You scored <b>192</b> points.</body></html>";
     webview.loadData(summary, "text/html", null);
    
    0 讨论(0)
提交回复
热议问题