Created
February 26, 2018 20:19
-
-
Save danielgomezrico/97838085d280e935e5fccab81fc0fd4c to your computer and use it in GitHub Desktop.
Extension to set a text with HTML tags on TextView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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