Android TextView 添加链接
2012-10-17 09:06
274 查看
使用autoLink,只要用这个属性,我们textview就可以添加链接了。
当我们在代码中写成android:autoLink="all"我们就可以在textview里面写的文字中包含网址、电话、email的会自动加入连接地址。
Java代码:
package eoe.link;
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
android:text="@string/link_text_auto" />
使用一个字符串资源含直接<一个>标签来说明链接。
Java代码:
packageeoe.link;
<stringname="link_text_manual">
<b>text2:</b>Thisissomeother
text,witha<ahref="http://www.google.com">link</a>specified
viaan<a>tag.Usea\"tel:\"URL
to<ahref="tel:4155551212">dialaphonenumber</a>.
</string>
TextViewt2=(TextView)findViewById(R.id.text2);
t2.setMovementMethod(LinkMovementMethod.getInstance());
建立了文本中使用HTML代码。
Java代码:
package eoe.link;
TextView t3 = (TextView) findViewById(R.id.text3);
t3.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."));
t3.setMovementMethod(LinkMovementMethod.getInstance());
当我们在代码中写成android:autoLink="all"我们就可以在textview里面写的文字中包含网址、电话、email的会自动加入连接地址。
Java代码:
package eoe.link;
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
android:text="@string/link_text_auto" />
使用一个字符串资源含直接<一个>标签来说明链接。
Java代码:
packageeoe.link;
<stringname="link_text_manual">
<b>text2:</b>Thisissomeother
text,witha<ahref="http://www.google.com">link</a>specified
viaan<a>tag.Usea\"tel:\"URL
to<ahref="tel:4155551212">dialaphonenumber</a>.
</string>
TextViewt2=(TextView)findViewById(R.id.text2);
t2.setMovementMethod(LinkMovementMethod.getInstance());
建立了文本中使用HTML代码。
Java代码:
package eoe.link;
TextView t3 = (TextView) findViewById(R.id.text3);
t3.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."));
t3.setMovementMethod(LinkMovementMethod.getInstance());
相关文章推荐
- android:为TextView添加样式——下划线,颜色,设置链接样式及前背景色
- Android 编程下 TextView 添加链接的一种方式
- Android高亮显示TextView某个单词,添加链接
- Android 编程下 TextView 添加链接的一种方式
- android:为TextView添加样式——下划线,颜色,设置链接样式及前背景色
- android:为TextView添加样式——下划线,颜色,设置链接样式及前背景色
- Android---10---TextView添加链接的两种方式
- Android TextView中添加链接并在链接部分字体变色可点击
- android:为TextView添加样式——下划线,颜色,设置链接样式及前背景色
- android:为TextView添加样式——下划线,颜色,设置链接样式及前背景色
- android:为TextView添加样式——下划线,颜色,设置链接样式及前背景色
- android:为TextView添加样式——下划线,颜色,设置链接样式及前背景色
- android:为TextView添加样式——下划线,颜色,设置链接样式及前背景色
- android:TextView中的文本链接之--设置超链接、颜色、字体等属性
- Android TextView中链接(link)点击事件的截取
- 为TextView添加样式——下划线,颜色,设置链接样式及前背景色
- Android textView文字添加图片 imageSpan使用
- android textView添加不同颜色的边框
- Android 在窗口的最前端添加TextView--windowManager.addView(textView, layoutParams)
- Android TextView 添加部分文字高亮,点击功能