【问题标题】:Android: How to convert local string(html) to html page and display in the WebviewAndroid:如何将本地字符串(html)转换为html页面并在Webview中显示
【发布时间】:2015-12-21 05:18:06
【问题描述】:

字符串包含 html 页面代码。根据要求,最好不要存储在文件中。如何在 Webview 中表示?

【问题讨论】:

  • 到目前为止你做了什么?

标签: android html webview


【解决方案1】:

您好,如果您的字符串包含 html 页面代码,那么您可以直接在 Webview 中加载,如下所示。

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

【讨论】:

    【解决方案2】:

    试试这个:

    WebView wv = (WebView)this.findViewById(R.id.myWebView);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.loadDataWithBaseURL(null, /*Your HTML string*/, "text/html", "utf-8", null);
    

    【讨论】:

      【解决方案3】:

      看看这个:http://developer.android.com/reference/android/webkit/WebView.html

      String summary = "<html><body>Your <b>HTML</b> code.</body></html>"; webview.loadData(summary, "text/html", null);

      更多参考请检查这个答案..

      https://stackoverflow.com/a/14002475/5362535

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多