在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());

更多相关文章

  1. Android(安卓)API中文文档EditText
  2. EditText 所有属性
  3. Android(安卓)使用 第三方 Sweet Alert Dialog 的时候出现的报错
  4. Edittext设置输入属性,包括使用代码设置
  5. Android(安卓)之 EditText属性用法介绍
  6. Android(安卓)TextView 换行
  7. Android(安卓)API中文文档EditText
  8. android TextView属性汇总
  9. ListView的使用

随机推荐

  1. Android中Touch事件流向
  2. Android(安卓)调用本地通讯录,广播接收
  3. IntentService原理
  4. android 卷轴视图(ScrollView)
  5. Android数据储存——Sqlite
  6. 导入Android(安卓)SDK中Sample下ApiDemos
  7. Android重写HorizontalScrollView模仿Vie
  8. android实现手机截屏并保存截图功能
  9. Android使用SoundPool播放短音效
  10. 【android笔记】android开发环境搭建--an