HTML列表标签不工作在Android中的TextView。我能做什么? [英] Html List tag not working in android textview. what can i do?

查看:166
本文介绍了HTML列表标签不工作在Android中的TextView。我能做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML列表标签不工作在Android中的TextView。这是我的字符串内容:

 字符串str =A考究采取经典格子条纹的软,纹理编织类似斜纹快来看看这一个实施; UL><李>内饰方面,剪裁合体的定制触感LT; /李><李>介质S $ P $垫领,一键式斜切桶箍< /李><李>应用门襟与珍珠母贝的真正的按键< /李><李取代;拆分后轭背面褶< /李><李>国产的100%进口棉花的美国和LT; /李>< / UL>中;
 

我在这样的文本视图装好了:

  textview.setText(Html.fromHtml(STR));
 

输出看起来像一个段落。我能做什么?是否有任何解决办法吗?

编辑:

  webview.loadData(STR,text / html的,UTF-8);
 

解决方案

正如你可以在<一见href="http://www.netmite.com/android/mydroid/frameworks/base/core/java/android/text/Html.java"><$c$c>Html类源$ C ​​$ C ,<一个href="http://developer.android.com/reference/android/text/Html.html#fromHtml%28java.lang.String%29"><$c$c>Html.fromHtml(String)不支持所有HTML标签。在这种非常情况下,&LT; UL&GT; &LT;李&GT; 不支持

从源头code我已经建立了允许HTML标签的列表:

  • BR
  • P
  • DIV
  • EM
  • B
  • 强烈
  • 引用
  • DFN
  • 字体
  • 块引用
  • TT
  • 等宽
  • A
  • U
  • SUP

所以你最好使用的WebView loadDataWithBaseURL 方法。尝试是这样的:

 字符串str =&LT; HTML&GT;&LT;身体GT; A考究采取经典格子条纹的软,纹理编织类似斜纹快来看看这个。 &LT; UL&GT;&LT;李&GT;修剪,剪裁合体的定制触感LT; /李&GT;&LT;李&GT;介质S $ P $垫领,一键式斜切桶箍&LT; /李&GT;&LT;李&GT;应用门襟正版母珍珠按钮和LT; /李&GT;&LT;李取代;拆分后轭背面褶&LT; /李&GT;&LT;李&GT;产地100%进口棉花的美国和LT; /李&GT;&LT; / UL&GT; &LT; /身体GT;&LT; / HTML&gt;中;
webView.loadDataWithBaseURL(NULL,STR,text / html的,UTF-8,NULL);
 

Html List tag not working in android TextView. This is my string content:

String str="A dressy take on classic gingham in a soft, textured weave of stripes that resembles twill.  Take a closer look at this one.<ul><li>Trim, tailored fit for a bespoke feel</li><li>Medium spread collar, one-button mitered barrel cuffs</li><li>Applied placket with genuine mother-of-pearl buttons</li><li>;Split back yoke, rear side pleats</li><li>Made in the U.S.A. of 100% imported cotton.</li></ul>";

I loaded it in a text view like this:

textview.setText(Html.fromHtml(str));

The output looks like a paragraph. What can I do? Is there any solution for it?

Edit:

webview.loadData(str,"text/html","utf-8");

解决方案

As you can see in the Html class source code, Html.fromHtml(String) does not support all HTML tags. In this very case, <ul> and <li> are not supported.

From the source code I have built a list of allowed HTML tags:

  • br
  • p
  • div
  • em
  • b
  • strong
  • cite
  • dfn
  • i
  • big
  • small
  • font
  • blockquote
  • tt
  • monospace
  • a
  • u
  • sup
  • sub

So you better use WebView and its loadDataWithBaseURL method. Try something like this:

String str="<html><body>A dressy take on classic gingham in a soft, textured weave of stripes that resembles twill.  Take a closer look at this one.<ul><li>Trim, tailored fit for a bespoke feel</li><li>Medium spread collar, one-button mitered barrel cuffs</li><li>Applied placket with genuine mother-of-pearl buttons</li><li>;Split back yoke, rear side pleats</li><li>Made in the U.S.A. of 100% imported cotton.</li></ul></body></html>";
webView.loadDataWithBaseURL(null, str, "text/html", "utf-8", null);

这篇关于HTML列表标签不工作在Android中的TextView。我能做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆