Android active link of url in TextView

After revisiting all solutions, a summary with some explanations:

android:autoLink="web" 

will find an URL and create a link even if android:linksClickable is not set, links are by default clickable. You don’t have to keep the URL alone, even in the middle of a text it will be detected and clickable.

<TextView
    android:text="My web site: www.stackoverflow.com"
    android:id="@+id/TextView1"
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
    android:autoLink="web">
</TextView>

To set a link via the code, same principle, no need for pattern or android:autoLink in layout, the link is found automatically using Linkify:

  final TextView myClickableUrl = (TextView) findViewById(R.id.myClickableUrlTextView);
  myClickableUrl.setText("Click my web site: www.stackoverflow.com");
  Linkify.addLinks(myClickableUrl, Linkify.WEB_URLS);

Leave a Comment