Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Created February 26, 2018 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielgomezrico/97838085d280e935e5fccab81fc0fd4c to your computer and use it in GitHub Desktop.
Save danielgomezrico/97838085d280e935e5fccab81fc0fd4c to your computer and use it in GitHub Desktop.
Extension to set a text with HTML tags on TextView
fun TextView.setHtmlText(text: String) {
val formattedText = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)
} else {
Html.fromHtml(text)
}
setText(formattedText, TextView.BufferType.SPANNABLE)
movementMethod = LinkMovementMethod.getInstance()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment