본문 바로가기
Android

Android Html tag in TextView

by 루에 2015. 2. 26.
반응형

Html Tag가 포함된 문자열 적용

Html.fromHtml(String)

eg) TextView.setText(Html.fromHtml(String)


링크(A Tag)적용

setMovementMethod()

eg) TextView.setMovementMethod(LinkMovementMethod.getInstance())

링크 외에도 몇 개 있음. 정리할 것


fromHtml의 적용 범위


Tags Supported in String Resources

Tags in static string resources are parsed by android.content.res.StringBlock, which is a hidden class. I've looked through the class and determined which tags are supported:

  • <a> (supports attributes "href")
  • <annotation>
  • <b>
  • <big>
  • <font> (supports attributes "height", "size", "fgcolor" and "bicolor", as integers)
  • <i>
  • <li>
  • <marquee>
  • <small>
  • <strike>
  • <sub>
  • <sup>
  • <tt>
  • <u>


Tags Supported by Html.fromHtml()

For some reason, Html.fromHtml() handles a different set of of tags than static text supports. Here's a list of the tags (gleaned from Html.java's source code):

  • <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>


The font "color" attribute supports some color names (along with the normal integer-based color scheme):

  • aqua
  • black
  • blue
  • fuchsia
  • green
  • grey
  • lime
  • maroon
  • navy
  • olive
  • purple
  • red
  • silver
  • teal
  • white
  • yellow


반응형

댓글