开发者

Android TextView with HTML & separator

I have a TextView that is part o开发者_开发百科f a ListView row item. In that TextView, i have some HTML rendered using Html.fromHtml(). I'm wondering if there is a way to do what is effectively an <hr> tag within the html so that it'll render a horizontal line in between 2 items within the TextView. is this even possible?


As you can see in the Html class source code, Html.fromHtml(String) does not support all HTML tags. This is 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, why don't just use a WebView instead of a TextView?


If you can figure out how to create a visual representation of an hr tag with Span objects then you can use the longer form of the fromHtml method and supply an instance of Html.TagHandler that will replace the hr tag with an Editable that represents that hr.


This is not supported. You can use Box Drawing Characters like (this is not the regular equal sign ) from Unicode to achieve something similar. However, your line won't fill the whole space.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜