Skip to content

Instantly share code, notes, and snippets.

@luck-alex13
Last active March 1, 2018 03:41
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 luck-alex13/f5307eb64741ddb18bf0a188cbc9d952 to your computer and use it in GitHub Desktop.
Save luck-alex13/f5307eb64741ddb18bf0a188cbc9d952 to your computer and use it in GitHub Desktop.
Default html and links support in TextView
textView.setText(fromHtml(text));
textView.setMovementMethod(LinkMovementMethod.getInstance());
public static Spanned fromHtml(String html) {
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(html);
}
return result;
}
//Important: Don't forget to remove autoLink="web" if you are calling setMovementMethod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment