I’m trying to add a link to a Twitter profile in an about box. ‘Regular’ links such as email address and web address are handled by
android:autoLink="email|web"
in about.xml, but for a Twitter profile page I need to use html code in my strings.xml. I’ve tried:
<string name="twitter">Follow us on <a href=\"http://www.twitter.com/mytwitterprofile">Twitter: @mytwitterprofile</a></string>
which renders html markup on the about box.
I’ve also tried:
<string name="twitter">Follow us on <a href="http://www.twitter.com/mytwitterprofile">Twitter: @mytwitterprofile</a></string>
which display the text “Follow us on Twitter: @mytwitterprofile”, but it is not a hyper-link.
How do I do this seemingly simple task!?
Cheers,
Barry
The simple answer is that the
TextViewdoes not support<a>tags. AFAIK, it only supports basic formatting such as<b>,<i>and<u>. However, if you supplyandroid:autoLink="web", the following string:Will turn
twitter.com/mytwitterprofileinto a proper link (when set via XML likeandroid:text="@string/twitter"; if you want to set it from code, you’ll need theHtml.fromHtmlmethod someone else posted in an answer).