TextView两种显示link的方法

一、简介

也是TextView显示文本控件两种方法

也是显示丰富的文本

二、方法

TextView两种显示link的方法

 1)通过TextView里面的类html标签
* 1、设置好html标签的文本

String text1="<font color='red'><i>你好啊,陌生人</i></font><br/>";
text1+="<a href='http://www.baidu.com'>百度</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 href='http://www.baidu.com'>百度</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>

TextView两种显示link的方法的更多相关文章

  1. Eclipse中SVN的安装步骤(两种)和使用方法

    Eclipse中SVN的安装步骤(两种)和使用方法 一.给Eclipse安装SVN,最常见的有两种方式:手动方式和使用安装向导方式.具体步骤如下: 方式一:手动安装 1.下载最新的Eclipse,我的 ...

  2. C#两种创建快捷方式的方法

    C#两种创建快捷方式的方法http://www.cnblogs.com/linmilove/archive/2009/06/10/1500989.html

  3. HTTP/HTTPS GET&POST两种方式的实现方法

    关于GET及POST方式的区别请参照前面文章:http://www.cnblogs.com/hunterCecil/p/5698604.html http://www.cnblogs.com/hunt ...

  4. iOS - UITableView中有两种重用Cell的方法

    UITableView中有两种重用Cell的方法: - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier; - (id)dequ ...

  5. 两种ps切图方法(图层/切片)

    两种Ps切图方法 一.      基础操作: a)    Ctrl++ 放大图片,ctrl - -缩小图片 b)    按住空格键space+,点击鼠标左键,拖动图片. c)    修改单位,点击编辑 ...

  6. Python_两种导入模块的方法异同

    Python中有两种导入模块的方法 1:import module 2:from module import * 使用from module import *方法可以导入独立的项,也可以用from m ...

  7. Tomcat下载安装并部署到IDEA(附带idea两种热部署设置方法)

    目录 Tomcat下载教程 Tomcat安装教程 Tomcat热部署到IDEA idea两种热部署设置方法 使用Idea的时候,修改了代码,需要反复的重启Tomcat,查看效果,是不是贼烦?还记得刚上 ...

  8. 接口测试中GET和POST两种基本HTTP请求方法的区别

    面试时,可以回答(一般答前4条就行): GET参数通过url传递,POST放在request body中 GET请求在url中传递的参数是有长度限制的,而POST没有 GET比POST更不安全,因为参 ...

  9. SSH简介及两种远程登录的方法

    出处 https://blog.csdn.net/li528405176/article/details/82810342 目录 SSH的安全机制 SSH的安装 启动服务器的SSH服务 SSH两种级别 ...

随机推荐

  1. 基于mondrain 的原理纠正特殊指标值

    原文地址:http://www.cnblogs.com/qiaoyihang/p/7348385.html 下面有两张表 数学试卷成绩 表1 学号 省份 批次 学校 试卷成绩 数学试卷小题成绩 表2 ...

  2. vue自定义全局和局部指令

    一.介绍 1.除了核心功能默认内置的指令 (v-model 和 v-show),Vue 也允许注册自定义指令. 2.自定义指令的分类       1.全局指令 2.局部指令 3.自定义全局指令格式 V ...

  3. MySQL -表完整性约束(Day41)

    阅读目录 一.介绍 二.not null 与 default 三.unique 四.primary key 五.auto_increment 六.foreign key 七. 总结 一 介绍 回到顶部 ...

  4. go——字典(二)

    字典是一种数据结构,用于存储一系列无序的键值对. 字典是基于键来存储值.字典功能强大的地方是能够基于键快速检索数据. 键就像索引一样,指向与键关联的值. 1.内部实现 字典是一个集合,可以使用类似处理 ...

  5. python2 跟3的区别

    1----python2:1 臃肿 , 源码的重复量很多2:语法不清晰,掺杂着 c,pyp,java,的一些陋习 python3: 几乎是重构后的源码,规范 清晰 优美 2.python的分类 分为编 ...

  6. Redis整合Spring实现缓存

    一.Redis介绍 什么是Redis? redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set( ...

  7. 3. Longest Substring Without Repeating Characters(最长子串,双指针+hash)

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  8. UEditor文本编辑器

    Ueditor是由百度web前端研发部开发所见即所得的编辑器,具有轻量,可定制,注重用户体验等特点.Ueditor基于BSD开源协议,除了具有代码精简.加载迅速的轻量级特质 外,还采用了分层理念,使开 ...

  9. LightOJ - 1356 Prime Independence (数论+二分图匹配)

    题意:有N个数的集合,其中选出若干个数组成一个子集,要求这个子集中的任意两个数a,b都不能通过a=k*b得到,其中k是一个素数.求这个子集最大的size. 分析:集合中任意两数的关系是二者之间是否之差 ...

  10. 亿能测试大讲堂 - YY在线课程[ 测试人员需要掌握的Shell脚本编程 ]

    亿能测试大讲堂 - YY在线课程[ 测试人员需要掌握的Shell脚本编程 ]http://automationqa.com/forum.php?mod=viewthread&tid=2453& ...