Try
txtTest.setText( Html.fromHtml("<a href=\"http://www.google.com\">Google</a>")); txtTest.setMovementMethod(LinkMovementMethod.getInstance());
Remember: do not use android: autoLink = "web" with it. because it calls LinkMovementMethod does not work.
Update for SDK 24 + The Html.fromHtml function has Html.fromHtml deprecated on Android N (SDK v24), so go ahead and use this method:
String html = "<a href=\"http://www.google.com\">Google</a>"; 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); } txtTest.setText(result) txtTest. setMovementMethod(LinkMovementMethod.getInstance());
Here is a list of flags:
FROM_HTML_MODE_COMPACT = 63; FROM_HTML_MODE_LEGACY = 0; FROM_HTML_OPTION_USE_CSS_COLORS = 256; FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE = 32; FROM_HTML_SEPARATOR_LINE_BREAK_DIV = 16; FROM_HTML_SEPARATOR_LINE_BREAK_HEADING = 2; FROM_HTML_SEPARATOR_LINE_BREAK_LIST = 8; FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM = 4; FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH = 1;
Nguyen Minh Binh Jan 04 '12 at 5:50 2012-01-04 05:50
source share