Skip to main content
Active reading [<https://en.wikipedia.org/wiki/XML>]. Used more standard formatting (we have italics and bold on this platform).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

The accepted answer is correct, BUTbut it will mean that phone numbers, maps, email addresses, and regular links, e.g., http://google.com without href tags will NO LONGERno longer be clickable since you can't have an autolink in the xmlXML content.

The only complete solution to have EVERYTHINGeverything clickable that I have found is the following:

Spanned text = Html.fromHtml(myString); URLSpan[] currentSpans = text.getSpans(0, text.length(), URLSpan.class); SpannableString buffer = new SpannableString(text); Linkify.addLinks(buffer, Linkify.ALL); for (URLSpan span : currentSpans) { int end = text.getSpanEnd(span); int start = text.getSpanStart(span); buffer.setSpan(span, start, end, 0); } textView.setText(buffer); textView.setMovementMethod(LinkMovementMethod.getInstance()); 

And the TextView should NOTnot have android:autolink. There's no need for android:linksClickable="true" either; it's true by default.

The accepted answer is correct, BUT it will mean that phone numbers, maps, email addresses, and regular links e.g. http://google.com without href tags will NO LONGER be clickable since you can't have autolink in the xml.

The only complete solution to have EVERYTHING clickable that I have found is the following:

Spanned text = Html.fromHtml(myString); URLSpan[] currentSpans = text.getSpans(0, text.length(), URLSpan.class); SpannableString buffer = new SpannableString(text); Linkify.addLinks(buffer, Linkify.ALL); for (URLSpan span : currentSpans) { int end = text.getSpanEnd(span); int start = text.getSpanStart(span); buffer.setSpan(span, start, end, 0); } textView.setText(buffer); textView.setMovementMethod(LinkMovementMethod.getInstance()); 

And the TextView should NOT have android:autolink. There's no need for android:linksClickable="true" either; it's true by default.

The accepted answer is correct, but it will mean that phone numbers, maps, email addresses, and regular links, e.g., http://google.com without href tags will no longer be clickable since you can't have an autolink in the XML content.

The only complete solution to have everything clickable that I have found is the following:

Spanned text = Html.fromHtml(myString); URLSpan[] currentSpans = text.getSpans(0, text.length(), URLSpan.class); SpannableString buffer = new SpannableString(text); Linkify.addLinks(buffer, Linkify.ALL); for (URLSpan span : currentSpans) { int end = text.getSpanEnd(span); int start = text.getSpanStart(span); buffer.setSpan(span, start, end, 0); } textView.setText(buffer); textView.setMovementMethod(LinkMovementMethod.getInstance()); 

And the TextView should not have android:autolink. There's no need for android:linksClickable="true" either; it's true by default.

Source Link

The accepted answer is correct, BUT it will mean that phone numbers, maps, email addresses, and regular links e.g. http://google.com without href tags will NO LONGER be clickable since you can't have autolink in the xml.

The only complete solution to have EVERYTHING clickable that I have found is the following:

Spanned text = Html.fromHtml(myString); URLSpan[] currentSpans = text.getSpans(0, text.length(), URLSpan.class); SpannableString buffer = new SpannableString(text); Linkify.addLinks(buffer, Linkify.ALL); for (URLSpan span : currentSpans) { int end = text.getSpanEnd(span); int start = text.getSpanStart(span); buffer.setSpan(span, start, end, 0); } textView.setText(buffer); textView.setMovementMethod(LinkMovementMethod.getInstance()); 

And the TextView should NOT have android:autolink. There's no need for android:linksClickable="true" either; it's true by default.