在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());
转自: http://shazhuzhu1.iteye.com/blog/960695

更多相关文章

  1. android在文本中添加超链接
  2. Android控件之EditText(输入文本框控件)
  3. 软键盘挡住文本框
  4. android中的文本框
  5. android 分段显示文本颜色控件
  6. 【Android常用控件】EditText常用属性【二】:为文本输入框指定软
  7. android 开发技巧(9)--为文本添加发亮的效果
  8. Android的文本系列的控件
  9. android开发_文本按钮 与 输入框

随机推荐

  1. ImageView ScaleType 属性值的意义
  2. Android(安卓)4.0 gallery2 生成video th
  3. Android中RelativeLayout及TableLayout使
  4. android DragLayer源码
  5. Android(安卓)service 服务 笔记
  6. android连接数据库
  7. Android(安卓)GreenDao3.2配置及使用详解
  8. Android(安卓)属性系统: Android(安卓)Pro
  9. ListView中item点击的时候颜色变化
  10. Android(安卓)View — Gradient 渐变