6

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,787
  • 2
  • 18
  • 34

4 Answers4

19

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,517
  • 8
  • 63
  • 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
  • All my "problems" with html text , spannables and weird weird link recognition where gone when simply removing all linkify methods and just setMovementMethod() ( with clickable , etc) – CaptainCrunch Mar 30 '23 at 20:13
17
 android:autoLink="web"
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Rohit Mandiwal
  • 10,258
  • 5
  • 70
  • 83
  • 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
  • 124,308
  • 23
  • 334
  • 268
0

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

Karan
  • 12,724
  • 6
  • 40
  • 33