所以我在Strings.xml中有这个:
<string name="sixpackInfo">
<html><body><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. </p>
<p><b>Sed dignissim lacinia nunc. Curabitur tortor.</b> Pellentesque nibh. Aenean quam. In sce
</body></html>
</string>
我尝试将此字符串加载并解析为webview。
像这样:wvInformation = (WebView) findViewById(R.id.wvInformation);
String text = getResources().getString(R.string.sixpackInfo);
System.out.println(text);
wvInformation.loadData(text, "text/html", null);
我将lorem ipsum文本添加到webview中,但是p标签和b标签没有得到处理。文本只显示为带有标记的纯文本。
答案 0 :(得分:5)
<string name="sixpackInfo">
<![CDATA[<html><body><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. </p>
<p><b>Sed dignissim lacinia nunc. Curabitur tortor.</b> Pellentesque nibh. Aenean quam. In sce
</body></html>
]]>
</string>
答案 1 :(得分:0)
听起来你的HTML片段没有被读取为HTML - 检查实际读取的内容(将其转储到文件中)并查看例如之前是否有任何内容。
答案 2 :(得分:-1)
试试这个 -
wvInformation.loadData(Html.fromHtml(text, "text/html", null);