在片段内的textview中创建超链接 [英] Creating a hyperlink within a textview inside a fragment

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

问题描述

我已经浏览了该站点上的许多线程,以找到解决我的问题的方法,但似乎没有一个起作用.目前,我可以在显示网站的同时创建超链接,例如-请转到此处- www.google.com (www.google.com已超链接).我想做的是将链接设为-请转到 此处 (此处是链接).下面是我尝试过的代码,但是一旦删除链接本身,"here"仍然像链接一样突出显示,但是没有任何功能.

I have looked through many of the threads on this site to find the solution to my problem but none seem to work. At the moment I am able to create a hyperlink while displaying the website eg - Please go here - www.google.com (The www.google.com is hyperlinked). What I am trying to do is have the link as - Please go here (Here is the link). Below is the code i have tried but once I remove the link itself, the 'here' still highlights like a link but has no function.

Strings.xml:

Strings.xml:

<string name="goog">Please go <a href="www.google.com">here</a></string>

fragment_home.xml:

fragment_home.xml:

 <TextView
    android:id="@+id/npd"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:autoLink="web"
    android:fontFamily="sans-serif-light"
    android:linksClickable="true"
    android:text="@string/npd"
    android:textColorLink="#FF0000"
    android:textSize="12dp" />

如果我在Strings.xml中将www.google.com更改为此处",则该链接会将我直接带到那里.有人能解决这个问题吗?预先感谢.

If i change 'here' for www.google.com within Strings.xml, the link takes me directly there. Has anyone been able to figure this problem out yet? Thanks in advance.

推荐答案

尝试一下,让我知道这是您正在寻找的东西

Try this and let me know is it what you are looking for

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));

这篇关于在片段内的textview中创建超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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