How can I make links in fromHTML clickable? (Android) How can I make links in fromHTML clickable? (Android) android android

How can I make links in fromHTML clickable? (Android)


As I assumed, the solution was trivial:

textView.setText(Html.fromHtml("<a href=\"http://www.google.com\">This is a link</a>"));textView.setMovementMethod(LinkMovementMethod.getInstance());

The second line somehow activates the link behavior, although I'm not quite sure how. The same question is addressed over at Google Code.


As mentioned in other answers, a way forward is to use:

xtView.setText(Html.fromHtml("<a href=\"http://www.google.com\">This is a link</a>"));textView.setMovementMethod(LinkMovementMethod.getInstance());

However, this won't work if you have ANY android:autoLink value set, not just 'web' as other comments seem to suggest. So that means you can use this solution to linkify URLs at the expense of having phone, email and maps being disabled/unlinked.


The javadoc of the LinkMovementMethod says that it

Supports clicking on links with DPad Center or Enter.

So it makes sense that works that way.

And confirmed, with 4.2.2 works like charm with just the

textView.setMovementMethod(LinkMovementMethod.getInstance());