代码之家  ›  专栏  ›  技术社区  ›  anonymous

为什么Html.fromHtml()不适用于<strike>或<s>或<del>标记

  •  -1
  • anonymous  · 技术社区  · 7 年前

    strikeThrough 上的文本 textView 从html文本。我试过其他的标签 bold , italic <strike> or <s> or <del> 标记文本它显示的文本没有 袭击 . 有人能帮我解决这个问题吗?

     String s="<p dir=\"ltr\"><del>a</del><del>b</del><del>c</del></p> ";
     txtView.setText(Html.fromHtml(s));
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Jacob Celestine Riya Solanki    7 年前

    简单地说,它是不受支持的。fromHtml()处理的标记集与静态文本支持的不同。下面是标签列表(我不知道是否完整):

    <a> (supports attribute "href")
    <b>
    <big>
    <blockquote>
    <br>
    <cite>
    <dfn>
    <div>
    <em>
    <font> (supports attributes "color" and "face")
    <i>
    <img> (supports attribute "src". Note: you have to include an ImageGetter to handle retrieving a Drawable for this tag)
    <p>
    <small>
    <strong>
    <sub>
    <sup>
    <tt>
    <u>
    

    你可以检查源代码 here

    您必须使用具有扩展功能的库才能使其工作,或者自己编写一个库。检查这个 one 或者这个 one . Github上还有很多其他的代码,如果你想写的话,我相信你可以通过google找到这些代码。