TextView中的Html字符串

时间:2012-07-17 11:03:45

标签: android android-layout

我有一个字符串,如下所示

<p><strong>Lorem Ipsum is simply dummy text</strong></p>
<table border="0">
<tbody>
<tr>enter code here
<td>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li>Ut imperdiet tortor sit amet enim bibendum eget fermentum lectus auctor.</li>
<li>Cras mattis mi nec dolor iaculis a rhoncus ligula lacinia.</li>
<li>Phasellus sit amet lorem ut nunc iaculis lacinia nec at diam.</li>
<li>Duis nec turpis ac diam vehicula malesuada.</li>
</ul>
</td>
<td>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li>Ut imperdiet tortor sit amet enim bibendum eget fermentum lectus auctor.</li>
<li>Cras mattis mi nec dolor iaculis a rhoncus ligula lacinia.</li>
<li>Phasellus sit amet lorem ut nunc iaculis lacinia nec at diam.</li>
<li>Duis nec turpis ac diam vehicula malesuada.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p><strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse interdum sem ante, scelerisque vehicula libero. Sed porttitor tincidunt lacus, et lacinia mauris placerat at. Fusce laoreet scelerisque turpis sit amet dignissim. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc mollis, urna sed adipiscing posuere, erat orci facilisis neque, quis fringilla ipsum neque ut libero. Sed eget arcu massa, sodales fermentum lorem. Morbi fringilla commodo magna lobortis porttitor. Etiam tortor elit, cursus non placerat vel, dapibus vitae velit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam euismod nisl vitae orci viverra imperdiet.</strong></p>

我想用HTML标签显示所有这些内容。

请帮帮我... 并且如果可以的话,请建议我以任何方式做。

4 个答案:

答案 0 :(得分:1)

尝试使用Html.fromHtml(yourHtml) ..
http://developer.android.com/reference/android/text/Html.html

答案 1 :(得分:1)

首先在真实的HTML中进行,即<>然后使用正则表达式删除HTML标记。

mTextView.setText(HTML.fromHtml("<p><strong>L...." ));
String regexNoHTML = "\\<.*?\\>";    
String finalStringNoHTML = mTextView.getText.replaceAll(noHTMLString, "");
mTextView.setText(finalStringNoHTML);

答案 2 :(得分:0)

您好,您可以分配如下

txtUpgrade.setText(Html.fromHtml(getString(R.string.upgrade_text)));

答案 3 :(得分:0)

首先将您的字符串值存储到一个变量中,然后使用下面的代码将此字符串显示为textview。

String s="&lt;li&gt;Duis nec turpis ac diam vehicula malesuada.&lt;/li&gt;";
mTxtView1.setText(Html.fromHtml(s));