从TextView文本

时间:2017-12-08 02:50:05

标签: android textview linkify autolink

我有一个带有以下单词的TextView:

  

Google LLC是一家123美国跨国技术456公司,专门从事互联网相关服务和产品。这些包括在线广告技术,搜索,云计算,软件和硬件。 Google由Larry Page和Sergey Brin于1998年创立,当时他们是博士。斯坦福大学的学生。请致电(123)4444-3343

我想将号码(123) 4444-3343设为可点击的号码,然后点击它会让用户进入呼叫模式。

我尝试过以下代码:

textView.setAutoLinkMask(Linkify.PHONE_NUMBERS);
textView.setMovementMethod(LinkMovementMethod.getInstance());

根本不起作用。我只希望(123)4444-3343可点击。我怎样才能做到这一点?感谢。

1 个答案:

答案 0 :(得分:1)

第一个选项你要将XML android:autoLink="phone"添加到textView

你拥有的第二个选项是使用Html.fromHtml

txt.setText(Html.fromHtml("..." +
                "Please call <a href=\"tel:123-456-7890\">(123) 456-7890</a>"));
        txt.setMovementMethod(LinkMovementMethod.getInstance());
        txt.setAutoLinkMask(Linkify.PHONE_NUMBERS);

另一种方式是使用 ClickableSpan 更多信息,你可以在这里找到 How to set the part of the text view is clickablehere