直接看效果:
其中点击 Email自动跳转到发送Email界面,点击电话,自动拨打电话等功能。
布局如下:mutli_textview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv1"
android:textSize="18dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:text="@string/hello"
/>
<TextView
android:textSize="18dp"
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
android:autoLink="all"
/>
</LinearLayout>
代码如下:
package geo.test.toeditxml;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
public class JustFortestXmlActivity extends Activity
{
private TextView tv1;
private TextView tv2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mutli_textview);
tv1 = (TextView) findViewById(R.id.tv1);
tv2 = (TextView) findViewById(R.id.tv2);
String strHtml = "<font color='red' >lixiaodaoaaa is a good boy</font></br>";
strHtml += "<big><a href='http://t.qq.com/lixiaodaoaaa'>欢迎访lixiaodaoaaa 的腾讯微博</a></big>";
String str2 = "我的空间地址是URL:http://blog.youkuaiyun.com/lixiaodaoaaa\n";
str2 += "我的email:lixiaodaoaaa@qq.com\n";
str2 += "我的电话是:+86 010-89497392";
tv1.setText(Html.fromHtml(strHtml));
tv1.setMovementMethod(LinkMovementMethod.getInstance());
tv2.setText(str2);
tv2.setMovementMethod(LinkMovementMethod.getInstance());
}
}
这里非常重要:tv1.setMovementMethod(LinkMovementMethod.getInstance());支持LInkMoveMent的动作。
这里也很重要(Html.fromHtml(strHtml));,将Html代码转换成丰富的文本进行显示。!