TextView add links
Description
You can invoke the static addLinks()
method of the Linkify class
to find and add links to the content of any TextView
or any Spannable on demand.
Linkify.addLinks(tv, Linkify.ALL);
Example
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
//w w w. j a v a 2 s . c o m
<TextView
android:id="@+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="abc@yourserver.com"
android:autoLink="email" />
</LinearLayout>
Java code
package com.java2s.app;
//from ww w .java 2 s. co m
import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.widget.TextView;
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView nameValue = (TextView)findViewById(R.id.myText);
Linkify.addLinks(nameValue, Linkify.ALL);
}
}