我有一个字符串,其中包含html文本和图像解析从一个json文件。我需要显示在webview.The字符串由3-4段组成,但在webview中显示它显示像一个段落,即安卓webview跳过隔断线tags.But我的要求是显示,因为它在网站上适当的alignment.Please帮助我。
我的Json文件链接是this
我的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);发布于 2012-11-16 15:47:45
问题出在您的json数据中的"\r\n“。看起来\r\n只有在标签中才能正常工作。简单解决方案将\r\n替换为
标签。
String all="<html><body>"+newsContent.replace("\r\n", "<br/>")+"</body></html>";
发布于 2017-09-21 00:42:51
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");https://stackoverflow.com/questions/13411464
复制相似问题