I know this is an old question, but this is a problem that I recently ran into, and I did not find the StackOverflow answer that helped me. Therefore, after extensive experiments, I found a solution and thought that I would share it with a descendant.
In your strings.xml file, use HTML tags and markers:
<string name="example"><![CDATA[I know hyperlinks in android can be placed with "Linkify".. and i have referred <a href="http://developer.android.com/reference/android/text/util/Linkify.html">android docs</a> page]]></string>
In your XML, make sure that no special attributes are added. DO NOT use android: autolink
In your Java code, you should use fromHtml, Linkify, and LinkMovementMethod. Be sure to call Linkify before LinkMovementMethod
exampleTextView.setText(Html.fromHtml(getString(R.string.example))); Linkify.addLinks(exampleTextView, Linkify.WEB_URLS); exampleTextView.setMovementMethod(LinkMovementMethod.getInstance());
Another caveat: if you use these HTML links where the link has display text that does not match the URL (Google and www.google.com), DO NOT put raw URLs in a string. So:
<string name="example"><![CDATA[www.google.com I know hyperlinks in android can be placed with "Linkify".. and i have referred <a href="http://developer.android.com/reference/android/text/util/Linkify.html">android docs</a> page]]></string>
Turn "www.google.com" into the link, but do not include the "android docs" in the link.
It was very difficult for me to figure it out, because I tried many different combinations and followed a lot of online examples, none of which worked until I found only the correct combination of magic described above. Hope this helps someone else!
Chad Schultz Apr 20 '16 at 20:49 2016-04-20 20:49
source share