在textView里能把显示的文本变成 URL地址,邮箱地址,电话 的超链接效果。
通过android:autoLink来设置(会自动识别字符串中匹配的字段)
其有这些属性值
None : 不匹配任何链接(默认)
web : 网址
email : 邮箱
phone : 电话号码
map : 匹配映射网址
all : 匹配所有链接
在.xml里写两个Textview的例子
<TextView
android:id="@+id/tv_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/tv_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="all"
/>
在.java里findViewById得到后
//超链接网站(没有设置android:autoLink时)
String text1="<a href='http://www.baidu.com'>百度</a>";
tv_a.settext(Html.fromHtml(text1));
//要有链接的效果还要加上这个
tv_a.setMovementMethod(LinkMovementMethod.getIntent);
//链接是个电话号码(android:autoLink="all")
String text2="我的网站:http://www.baidu.com 我的电话:110";
tv_b.setText(text2);
tv_b.setMovementMethod(LinkMovementMethod.getIntent);
大致效果这样 百度 和下面的网址能跳转到百度网站,电话号码能跳到系统拨号器