在TextView中使用超级连接有几种方式:
1.在属性中设置:
<TextView
android:id="@+id/testweb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web" //是将文本的web网址解释成超链接
android:text="@string/link_text_auto"
/>
autoLink:一共有几种值:web,phone,map,email.all.none.

分别是url连接。电话号码提取拨号,地图地址。电子邮件,全部解释就是能支持的超级连接全部起作用,
none就是默认 情况。没有超链接,
2.使用html文本:
例如:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="link_text_manual">
a <a href="http://www.google.com">link</a> specified
via an <a> tag.Use a \"tel:\" URL
to <a href="tel:4155551212">dial a phone number</a>.
</string>
</resources>


<TextView
android:id="@+id/testemail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/link_text_manual"
/>
3.在java代码中添加超级连接:
TextView t = (TextView) findViewById(R.id.text3);
t.setText(
Html.fromHtml(
"<b>text3:</b>Text with a " +
"<a href=\"http://www.google.com\">link</a> " +
"created in the Java source code using HTML."));
t.setMovementMethod(LinkMovementMethod.getInstance());
使用:SpannableString
SpannableString ss = new SpannableString("Click here to dial the phone.");
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new URLSpan("tel:4155551212"), 13, 17, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView t = (TextView) findViewById(R.id.text4);
t.setText(ss);
t.setMovementMethod(LinkMovementMethod.getInstance());

[原创] android 文本中使用超链接
http://www.cmd100.com/bbs/thread-5579-1-1.html

更多相关文章

  1. Android应用程序开发入门
  2. android中shape的使用(android:angle小解)
  3. Android学习笔记(二八):字体
  4. android 自带的主题 theme 的使用
  5. android studio编译android M时无法使用org.apache.http.**的解
  6. android ellipsize的使用
  7. android hierarchyViewer 的UI工具的使用
  8. 使用Android(安卓)NDK编译OpenCV应用
  9. android

随机推荐

  1. Android预定义样式?android:attr/attribu
  2. android之CalendarView日历视图
  3. Android之隐式意图(Intent)如何查找匹配
  4. Android开发之如何获取Android手机屏幕的
  5. 【android开发】解析xml文件①
  6. Android(安卓)imageview图片缩放实现
  7. Unity和Android交互(持续更新)
  8. Android(安卓)Layout的layout_height等属
  9. 如何使用自己的makefile编译android ndk
  10. Android异步任务AsyncTask