0

json ファイルから解析された html テキストと画像を含む文字列がありますwebview。要件は、適切な配置でウェブサイトにそのまま表示することです。助けてください。webviewwebview

私のJsonファイルのリンクはこれです

そして私のwebviewコードは

//newsContent contains the json string after parsing.

  String all="<html><body>"+newsContent+"</body></html>";

                 tv.getSettings().setJavaScriptEnabled(true); 
                 tv.getSettings().setPluginsEnabled(true);
                 tv.getSettings().setSupportZoom(false);
                 tv.getSettings().setAllowFileAccess(true);
                 WebSettings webSettings = tv.getSettings();
                 tv.getSettings().setAllowFileAccess(true);
                 webSettings.setTextSize(WebSettings.TextSize.NORMAL);

                 tv.loadDataWithBaseURL(null,all, "text/html", "UTF-8", null);
4

3 に答える 3

4

問題は、json データの "\r\n" にあります。タグでラップされている場合にのみ \r\n 機能するように見えます。簡単な解決策は、 \r\n を
タグに置き換えることです。

String all="<html><body>"+newsContent.replace("\r\n", "<br/>")+"</body></html>";

于 2012-11-16T07:47:44.680 に答える
0
String text = "<html><body style=\"text-align:justify\"> %s </body></Html>";
String data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac quam risus, at tempus justo. Sed dictum rutrum massa eu volutpat. Quisque vitae hendrerit sem.";
WebView webView = (WebView) findViewById(R.id.WebView);
webView.loadData(String.format(text, data), "text/html", "utf-8");
于 2017-09-20T16:42:50.840 に答える