5

I have a text view with text" This is a product developed by XYZ. For more queries, mail us at info@abc.com. And I have linkified "info@abc.com". But the problem is, whenever I touch any area below the textview, it gets linked to the email. How Do I make sure, the link has to happen only on clicking info@....I used patterns, Linkify.EMAIL_ADDRESS..nothing seem to work...kindly suggest some answers

Rashmi.B
  • 1,779
  • 2
  • 18
  • 34

4 Answers4

18

I had problems with automatic links, so I turned it off and instead I am using html formating of the text plus this code:

TextView textView = (TextView) findViewById(R.id.TextBox);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(Html.fromHtml(strText));

An email link goes <a href="mailto:my@email.com">my@email.com</a>

Lumis
  • 21,237
  • 8
  • 61
  • 67
  • Works, but the text is rendered with an underline. How to remove it? – Shane Oliver Mar 24 '11 at 11:36
  • Here is one way to do it: http://stackoverflow.com/questions/4096851/remove-underline-from-links-in-textview-android – Lumis Mar 24 '11 at 14:17
  • 2
    Took me an hour to figure it out, but it CRITICAL to call setMovementMethod BEFORE setText on the TextView. Good example. – Issa Fram Apr 26 '12 at 04:51
17
 android:autoLink="web"
Nimantha
  • 5,793
  • 5
  • 23
  • 56
Ashish
  • 9,878
  • 5
  • 65
  • 79
  • 3
    This only works for links that are the url themself. With this you cannot f.e. link the word `Google` to `google.com`. – Steven Roose Sep 14 '12 at 23:12
0

Method using Linkify Class:

myTextView.setAutoLinkMask(Linkify.EMAIL_ADDRESSES);
myTextView.setLinksClickable(true);
Jorgesys
  • 119,885
  • 23
  • 317
  • 256
0

Try using HTML formatting i.e. anchor tag for the link.

Karan
  • 12,594
  • 6
  • 38
  • 33