【问题标题】:Auto link property different text with the actual linking (setAutoLinkMask)自动链接属性与实际链接不同的文本 (setAutoLinkMask)
【发布时间】:2012-06-11 21:18:25
【问题描述】:

例如

TextView tv =(TextView)this.findViewById(R.id.tv);
tv.setAutoLinkMask(Linkify.ALL);
tv.setText("visit website, http://www.google.com");

http://www.google.com 将带我到http://www.google.com。 我想做的事情是这样的

TextView tv =(TextView)this.findViewById(R.id.tv);
tv.setAutoLinkMask(Linkify.ALL);
tv.setText("visit this website");

然后按“这个”我想带我去http://www.google.com

我该怎么做? (有可能吗?)

【问题讨论】:

    标签: android hyperlink


    【解决方案1】:

    来自 API 演示,

    TextView t3 = (TextView) findViewById(R.id.text3);
    t3.setText(Html.fromHtml(
                        "<b>text3:</b>  Text with a " +
                        "<a href=\"http://www.google.com\">link</a> " +
                        "created in the Java source code using HTML."));
    t3.setMovementMethod(LinkMovementMethod.getInstance());
    

    【讨论】:

      【解决方案2】:

      您可以只使用属性android:text="@string/url" 作为TextView 属性。确保将有效的 URL 作为 TextView 的值。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-03
        • 1970-01-01
        • 2015-11-30
        • 2023-03-12
        • 2017-04-02
        相关资源
        最近更新 更多