最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android TextView實(shí)現(xiàn)帶鏈接文字事件監(jiān)聽的三種常用方式示例

 更新時(shí)間:2017年08月23日 08:56:49   作者:遲做總比不做強(qiáng)  
這篇文章主要介紹了Android TextView實(shí)現(xiàn)帶鏈接文字事件監(jiān)聽的方法,結(jié)合實(shí)例形式分析了鏈接跳轉(zhuǎn)、setMovementMethod及布局屬性設(shè)置三種常用的實(shí)現(xiàn)方式,需要的朋友可以參考下

本文實(shí)例講述了Android TextView實(shí)現(xiàn)帶鏈接文字事件監(jiān)聽的三種常用方式。分享給大家供大家參考,具體如下:

/**
 * TextView實(shí)現(xiàn)文字鏈接跳轉(zhuǎn)功能
 * @description:
 * @author ldm
 * @date 2016-4-21 下午4:34:05
 */
public class TextViewLinkAct extends Activity {
  private TextView tv_3;
  private TextView tv_4;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.link);
    setTextViewLink();
  }
  /**
   * 通過不同方式實(shí)現(xiàn)TextView中文字點(diǎn)擊鏈接跳轉(zhuǎn)功能
   *
   * @description:
   * @author ldm
   * @date 2016-4-21 下午4:24:13
   */
  private void setTextViewLink() {
    // 以Html格式href鏈接方式實(shí)現(xiàn)跳轉(zhuǎn)
    tv_3 = (TextView) findViewById(R.id.text3);
    tv_3.setText(Html
        .fromHtml("<b>text3: Constructed from HTML programmatically.</b> Text with a "
            + "<a href=\"http://www.google.com\">link</a> "
            + "created in the Java source code using HTML."));
    tv_3.setMovementMethod(LinkMovementMethod.getInstance());
    // 通過SpannableString的setMovementMethod方法實(shí)現(xiàn)鏈接效果
    SpannableString ss = new SpannableString(
        "text4: Manually created spans. Click here to dial the phone.");
    ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 30,
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    ss.setSpan(new URLSpan("tel:4155551212"), 31 + 6, 31 + 10,
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv_4 = (TextView) findViewById(R.id.text4);
    tv_4.setText(ss);
    tv_4.setMovementMethod(LinkMovementMethod.getInstance());
  }
}

布局文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" >
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:divider="?android:attr/listDivider"
    android:orientation="vertical"
    android:showDividers="middle" >
    <!-- 通過在布局中autoLink屬性設(shè)置TextView的鏈接功能. -->
    <TextView
      android:id="@+id/text1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:autoLink="all"
      android:paddingBottom="8dp"
      android:text="&lt;b>text1: Various kinds
   of data that will be auto-linked.&lt;/b> In
   this text are some things that are actionable. For instance,
   you can click on http://www.google.com and it will launch the
   web browser. You can click on google.com too. If you
   click on (415) 555-1212 it should dial the phone. Or just write
   foobar@example.com for an e-mail link. If you have a URI like
   http://www.example.com/lala/foobar@example.com you should get the
   full link not the e-mail address. Or you can put a location
   like 1600 Amphitheatre Parkway, Mountain View, CA 94043. To summarize:
   https://www.google.com, or 650-253-0000, somebody@example.com,
   or 9606 North MoPac Expressway, Suite 400, Austin, TX 78759."
      android:textAppearance="?android:attr/textAppearanceMedium" />
    <TextView
      android:id="@+id/text3"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="8dp"
      android:paddingTop="8dp"
      android:textAppearance="?android:attr/textAppearanceMedium" />
    <TextView
      android:id="@+id/text4"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingTop="8dp"
      android:textAppearance="?android:attr/textAppearanceMedium" />
  </LinearLayout>
</ScrollView>

其中通過在而已代碼中android:autoLink屬性的選項(xiàng)目有:none(無鏈接效果),web(網(wǎng)頁(yè)鏈接),email(發(fā)郵件),phone(打電話),map(定位)及all(默認(rèn)全都自動(dòng)鏈接)。

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

安仁县| 临高县| 昌邑市| 镇原县| 禹城市| 康平县| 渝北区| 临沂市| 黄梅县| 重庆市| 井陉县| 湖南省| 武宁县| 望谟县| 白银市| 靖州| 雅安市| 牟定县| 鸡西市| 郸城县| 红河县| 桂平市| 罗甸县| 三亚市| 南召县| 绍兴市| 南京市| 云安县| 闵行区| 岢岚县| 蒲江县| 分宜县| 渭源县| 浦城县| 永和县| 韶关市| 晋中市| 怀宁县| 耿马| 阜宁县| 南江县|