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
Asked
Active
Viewed 1.0k times
5
-
**[Custom Link Patterns Using Regular Expression](http://www.indelible.org/ink/android-linkify/) might be helpful** – Vikas Patidar Feb 18 '11 at 14:11
4 Answers
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
-
2Took 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
-
3This 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