1、使用android:autoLink="all"只需在TextView中加入这个属性,而在TextView里面写的文字中包含网址、电话、email的会自动加入连接地址。

如:

<TextViewxmlns: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"

/>

2、使用<stringname=””><ahref=””></a></string>标签,建立超链接:

如:

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

3、在java文件中使用HTML语言:

如:

TextViewt3=(TextView)findViewById(R.id.text3);

t3.setText(Html.fromHtml("<b>text3:</b>Textwitha"

+"<ahref=\"http://www.google.com\">link</a>"

+"createdintheJavasourcecodeusingHTML."));

t3.setMovementMethod(LinkMovementMethod.getInstance());

4、字符串截取方法

SpannableStringss=newSpannableString("text4:Clickheretodialthephone.");

ss.setSpan(newStyleSpan(Typeface.BOLD),0,6,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

ss.setSpan(

newURLSpan("tel:4155551212"),13,17,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

TextViewt4=(TextView)findViewById(R.id.text4);

t4.setText(ss);

t4.setMovementMethod(LinkMovementMethod.getInstance());

5、Android中我们为了实现文本的滚动可以在ScrollView中嵌入一个TextView,其实TextView自己也可以实现多行滚动的,毕竟ScrollView必须只能有一个直接的子类布局。只要在layout中简单设置几个属性就可以轻松实现

<TextView

android:id="@+id/tvCWJ"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:scrollbars="vertical"<!--垂直滚动条-->

android:singleLine="false"<!--实现多行-->

android:maxLines="15"<!--最多不超过15-->

android:textColor="#FF0000"

/>

当然我们为了让TextView动起来,还需要用到TextViewsetMovementMethod方法设置一个滚动实例,代码如下

TextViewtvAndroid123=(TextView)findViewById(R.id.tvCWJ);

tvAndroid123.setMovementMethod(ScrollingMovementMethod.getInstance());

ad_link=(TextView)findViewById(R.id.ad_link);

ad_link.setText(Html.fromHtml("<ahref="\"mce_href="\"""+mURL.getLink()+"\">"+Html.fromHtml(mURL.getLabel()+"</a>")));

ad_link.setMovementMethod(LinkMovementMethod.getInstance());


更多相关文章

  1. android内核编译方法 转载
  2. Android梳理不常用widget篇
  3. EditText的imeOptions属性的设置
  4. Android(安卓)Hook神器:XPosed入门与登陆劫持演示
  5. android基本布局
  6. Android深入讲解WebView——下
  7. android parcelable 详细介绍
  8. java解析json字符串的两种方法详解(Android通用)
  9. [置顶] Android:图解Activity启动流程源码(整体流程)

随机推荐

  1. android圆形进度条颜色的设置
  2. android相对布局属性详解
  3. EditText 的属性
  4. android:toXDelta="-100%p"
  5. Android应用开发——系统自带样式Android
  6. 微信进入消息页面,光标处自动弹出软键盘设
  7. [置顶] Android系统的样式style
  8. Android应用开发——系统自带样式Android
  9. 如何实现友盟第三方登录与分享
  10. android中的style部分属性值介绍