我正在做一个项目,我正在接收一些我应该在WebView
. 问题是 html 字符串仅包含正文部分,没有任何标签<html>, <head>, <body>
,当我尝试在 webView 中显示接收到的字符串时,结果显示从服务器接收到的 html 字符串中包含的标签。
这是我收到的和正在做的一些例子:
从服务器收到的 Html 字符串:
05-30 14:02:56.785: D/(16970): body : <p align='justify'>The so-called Fiscal Compact is unlikely to be approved by the Latvian parliament in the second and final reading as four opposition MPs said that they would not back the initiative, local media reported on Tuesday evening. The second reading is scheduled for May 31. Under local legislation, the bill should be backed by 67 MPs in the 100-seat parliament, though the ruling coalition controls only 56 seats and depends on the opposition Union of Greens and Farmers (ZZS) to approve it. During the first reading 68 MPs backed the bill. The four MPs from ZZS will meet PM Dombrovskis later today to discuss the issue. They want more clarity about the country’s participation in neighboring Lithuania’s nuclear power plant project. Previously, ZZS said it extends its support on condition that the government fights for higher subsidies for farmers in the 2014-2020 EU budget framework.</p>
这是我的代码:
String bodyTxt = cursor.getString(cursor.getColumnIndex("body"));
Log.d("","body : "+bodyTxt);
String newBody = "<html><body>" + bodyTxt + "</body></html>";
body.loadDataWithBaseURL(null, newBody, "text/html", "utf-8", null);
结果是这样的:
我试过使用body.loadData(newBody, "text/html", "UTF-8");
,但这种方式甚至没有显示结果。
那么我做错了什么想法,我该如何解决这个问题?
提前致谢!