国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

TextView顯示文本控件兩種方法 TextView顯示link的方法

2019-12-12 02:19:02
字體:
來源:轉載
供稿:網友

一、簡介

也是TextView顯示文本控件兩種方法

也是顯示豐富的文本

 二、方法

 TextView兩種顯示link的方法

 1)通過TextView里面的類html標簽

* 1、設置好html標簽的文本

String text1="<font color='red'><i>你好啊,陌生人</i></font><br/>";
text1+="<a >百度</a><br />";

* 2、為之前的文本聲明Html.fromHtml,方便TextView解析為html標簽

tv_one.setText(Html.fromHtml(text1));

* 3、設置link點擊事件

tv_one.setMovementMethod(LinkMovementMethod.getInstance());

 2)通過android:autoLink屬性

* 1、添加普通文本

String text2="我的網站:http://www.baidu.com /n";
text2+="我的電話:18883306749";
tv_two.setText(text2);

* 2、在layout的textView中設置android:autoLink屬性

android:autoLink="all"

 三、代碼實例

點擊上面的百度和下面的百度鏈接。出現

點擊電話號碼。出現

代碼:

fry.Activity01

package fry;import com.example.textViewDemo1.R;import android.app.Activity;import android.os.Bundle;import android.text.Html;import android.text.method.LinkMovementMethod;import android.widget.TextView;public class Activity01 extends Activity{  private TextView tv_one;  private TextView tv_two;  @Override  protected void onCreate(Bundle savedInstanceState) {    // TODO Auto-generated method stub    super.onCreate(savedInstanceState);    setContentView(R.layout.activity01);        tv_one=(TextView) findViewById(R.id.tv_one);    tv_two=(TextView) findViewById(R.id.tv_two);        /*     * TextView兩種顯示link的方法     * 1)通過TextView里面的類html標簽     * 1、設置好html標簽的文本     * 2、為之前的文本聲明Html.fromHtml,方便TextView解析為html標簽     * 3、設置link點擊事件     *      * 2)通過android:autoLink屬性     * 1、添加普通文本     * 2、在layout的textView中設置android:autoLink屬性     *      */        //通過TextView里面的類html標簽來實現顯示效果    String text1="<font color='red'><i>你好啊,陌生人</i></font><br/>";    text1+="<a >百度</a><br />";        tv_one.setText(Html.fromHtml(text1));    //設置鼠標移動事件,產生鏈接顯示,沒有這句話,進不去百度    tv_one.setMovementMethod(LinkMovementMethod.getInstance());        //tv_two里面設置了android:autoLink="all",也就是自動顯示所有link    String text2="我的網站:http://www.baidu.com /n";    text2+="我的電話:18883306749";    tv_two.setText(text2);    //因為我設置了android:autoLink屬性,故不需要下面這句也可以進百度頁面,進電話頁面    //tv_two.setMovementMethod(LinkMovementMethod.getInstance());              }}

/textViewDemo1/res/layout/activity01.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical" >  <TextView    android:id="@+id/tv_one"    android:layout_width="match_parent"    android:layout_height="wrap_content" />    <TextView    android:id="@+id/tv_two"    android:layout_width="match_parent"    android:layout_height="wrap_content"     android:autoLink="all"    /></LinearLayout>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 政和县| 尼木县| 绥芬河市| 安化县| 渭源县| 梁河县| 阿拉善盟| 盐城市| 隆化县| 泰州市| 安义县| 永定县| 化隆| 贵州省| 开阳县| 太仓市| 密云县| 华池县| 汉源县| 海南省| 五大连池市| 剑阁县| 藁城市| 拜泉县| 嘉禾县| 琼海市| 曲靖市| 玛多县| 乌海市| 石阡县| 工布江达县| 抚宁县| 普兰县| 鹤山市| 邛崃市| 莱芜市| 德昌县| 且末县| 石台县| 托克逊县| 习水县|