Android TextView超链接 [英] Android TextView Hyperlink

查看:171
本文介绍了Android TextView超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用包含两个超链接的字符串实现TextView,如下所示,但链接没有打开新的浏览器窗口:

I'm implementing a TextView with a string containing two hyperlinks as below but the links are not opening a new browser window:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:textColor="#ffffff"
        android:paddingLeft="50dp"
        android:paddingRight="50dp"
        android:textSize="14sp"
        android:clickable="true"
        android:linksClickable="true"
        android:textColorLink="@color/colorPrimary"
        android:autoLink="web"
        android:text="@string/agree_terms_privacy"/>

在string.xml中

In string.xml

<string name="agree_terms_privacy">By continuing, you agree to our <a href="http://link1/terms">Terms of Use</a> and read the <a href="http://link1/privacy">Privacy Policy</a></string>


推荐答案

看看下面的代码片段,希望它有所帮助,

Have a look on below code snippet, hope it helps,

TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));

这篇关于Android TextView超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆