• Android textView 添加超链接(两种实现方式)


    在textView添加超链接,有两种方式,第一种通过HTML格式化你的网址,一种是设置autolink,让系统自动识别超链接,下面为大家介绍下这两种方法的实现

    第一种 

    TextView textView = new TextView(this); 
    String html = "有问题: "; 
    html+="http://www.baidu.com";//注意这里必须加上协议号,即http://。 
     //否则,系统会以为该链接是activity,而实际这个activity不存在,程序就崩溃。 
    CharSequence charSequence = Html.fromHtml(html);  
    textView.setText(charSequence);  
    textView.setMovementMethod(LinkMovementMethod.getInstance()); 
     
    第二种
    TextView textView = new TextView(this); 
    String html = "有问题: "; 
    html+="www.baidu.com";//这里即使不加协议好HTTP;也能自动被系统识别出来。 
    textView.setText(html); 
    textView.setAutoLinkMask(Linkify.ALL); 
    textView.setMovementMethod(LinkMovementMethod.getInstance()); 
     //也可以在布局文件中设置,TextView  android:autoLink="web"
     
    http://blog.sina.com.cn/s/blog_618199e60101rfw5.html
  • 相关阅读:
    (转)静态方法与实例方法
    使用C#和Excel进行报表开发(8)
    js千分位
    各种语言多态性比较
    中国互联网100个Web2.0网站名单
    HDU4405 期望
    HDU1266 字符串逆转
    POJ1087 DInic
    POJ1003 水~
    HDU4403 DFS
  • 原文地址:https://www.cnblogs.com/tmlee/p/4991223.html
Copyright © 2020-2023  润新知