суббота, 6 апреля 2013 г.

Android snippet: Linkify your Text Views

Linkify is a helper class that creates hyperlinks within Text View class trough RegEx pattern matching.

The Linkify class has presets that can detect and linkify web URLs, emails addresses and phone numbers. To apply a preset, use the static Linkify.addLinks method, passing in a View to Linkify and a bitmask of one of the following self-describing Linkify class constants: WEB_URLS, EMAIL_ADDRESSES, PHONE_NUMBERS and ALL.

TextView textView = (TextView) findViewById(R.id.myTextView);

Linkify.addLinks(textView, Linkify.WEB_URLS|Linkify.EMAIL_ADDRESSES);

You can also linkify Views directly within a layout using the android:autoLink attribute. It supports one or more of the following values: none, web, email, phone, all.





android:autolink="phone | email"