简体   繁体   English

android在textView上设置链接

[英]android set a link on a textView

I'm trying to attach a link to a TextView. 我正在尝试将链接附加到TextView。 But I can't seem to get it to work. 但是我似乎无法使其正常工作。

Here's the TextView 这是TextView

<TextView
       android:id="@+id/terms"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:gravity="center"
       android:clickable="true"
       android:linksClickable="true"
       android:text="@string/terms" />

And here's the setLink() method 这是setLink()方法

private void setLinks(){
        String termsURI = "";
        TextView termsTextView = (TextView) findViewById(R.id.terms);
        String termsLink = "<a href='www.google.com'>terms test</a>";
        termsTextView.setMovementMethod(LinkMovementMethod.getInstance());
        termsTextView.setText(Html.fromHtml(termsLink));
    }

I've tried 我试过了

How do I make links in a TextView clickable? 如何使TextView中的链接可点击?

I want text view as a clickable link 我希望将文本视图作为可点击的链接

Android TextView Hyperlink Android TextView超链接

All 3 are highly reviewed and did not work for me. 这3个都受到高度审查,对我不起作用。 Which leads me to believe I'm doing something wrong. 这使我相信我做错了什么。

Is there something wrong here? 这里有什么问题吗? or possibly some tips? 或一些技巧?

One thing to add, I need to be able to set the link in a method, since our live and debug environment differ. 要添加的一件事是,由于我们的实时环境和调试环境不同,因此我需要能够在方法中设置链接。 (different domains) (不同的域)

Maybe you missed "http://" in the URL string. 也许您错过了URL字符串中的“ http://”。

Please try this one: 请试试这个:

String termsLink = "<a href='http://www.google.com'>terms test</a>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM