Style your TextView with HTML tags

If you ever wondered if you can style your text with HTML tags – you absolutely can. For most cases it is enough to use Html.fromHtml or you can use it directly in your string resources. Here are the most used tags:

  • Bold: <b><em>
  • Italic: <i><cite><dfn>
  • 25% increase in text size <big>
  • 20% decrease in text size <small>
  • Setting font properties: <font face=”font_family“ color=”hex_color”>. Examples of the possible font families include monospaceserif and sans_serif.
  • Setting a monospace font family: <tt>
  • Strikethrough: <s><strike><del>
  • Underline: <u>Superscript: <sup>
  • Subscript: <sub>
  • Bullet points: <ul><li>
  • Line breaks: <br>
  • Division: <div>
  • CSS style: <span style=”color|background_color|text-decoration”>
  • Paragraphs: <p dir=”rtl | ltr” style=”…”>
    examples taken from this great article: https://medium.com/androiddevelopers/styling-internationalized-text-in-android-f99759fb7b8f

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *