android - Html 列表标签在 android textview 中不起作用。我能做些什么

Html 列表标签在 android TextView 中不起作用。这是我的字符串内容:

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>";

我将它加载到这样的 TextView 中:

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

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

编辑:

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

最佳答案

正如您在 Html class source code 中所见, Html.fromHtml(String) 不支持所有 HTML 标签。在这种情况下,<ul><li>不支持。

从源代码中我建立了一个允许的 HTML 标签列表:

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

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

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);

关于android - Html 列表标签在 android textview 中不起作用。我能做些什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3150400/

相关文章:

android - 同步 ScrollView 滚动位置 - android

android - 使用按钮背景颜色为我的按钮添加波纹效果?

android - 如何在 Activity 启动时在 ScrollView 中滚动到底部

android - 带有完成操作按钮的多行 EditText

android - 如何检测Android中布局的方向变化?

android - 带有阴影的自定义 ImageView

android - 获取 backstack 中的最新 fragment

android - 如何检查 Activity 是在前台还是在可见背景中?

android - SearchView 的 OnCloseListener 不起作用

android - 无法修改 ListView 中的 ArrayAdapter : Unsuppor