Search code examples
androidtextviewlinkify

Clickable URLs in TextView


I can't figure out how to use Linkify for my TextView. I'm currently trying:

Linkify.addLinks(myTextView, Pattern.compile("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"), "http://");

I am using this post for my regex, which checks out here.

Am I missing something that I have to do in order to have URLs in my TextView clickable?

Essentially, I am hoping to have my TextView show my URLs as clickable links and actually click through, just like iOS's UITextViews are able to by changing the dataDetectorTypes property to match the proper UIDataDetectorType.


Solution

  • If you want to use Linkfy there should be no need to write an own regex pattern for web urls, just use

     Linkify.addLinks(text, Linkify.WEB_URLS);