Android Linkify - 可点击的电话号码 [英] Android Linkify - Clickable telephone numbers

查看:301
本文介绍了Android Linkify - 可点击的电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图添加这样的功能,当您点击电话号码时,它会带您到预先填充号码的拨号器应用程序。我有以下代码:

So I am trying to add the functionality that when you click on a phone number it would take you to the Dialer app with the pre-populated number. I have the code below:

mContactDetailsText.setText(phonetextBuilder.toString());
            Pattern pattern = Pattern.compile("[0-9]+\\s+[0-9]+");
            Linkify.addLinks(mContactDetailsText, pattern, "tel:");

,文字目前为T. 0123 4567890

and the Text is currently "T. 0123 4567890"

目前的结果是只有上面的字符串而不是可点击的。我甚至尝试添加以下行,但没有运气:

The current outcome is just having the above string without it being clickable. I have even tried added the following line, but to no luck:

mContactDetailsText.setAutoLinkMask(0);

任何人有任何想法或者能看出我做错了什么?

Anyone got any ideas or can see what I am doing wrong?

谢谢

推荐答案

自动链接掩码需要包含搜索电话号码:

The autolink mask needs to include a search for phone numbers:

mContactDetailsText.setAutoLinkMask(Linkify.PHONE_NUMBERS);

然后您需要将链接设置为可点击:

Then you'll need to set the links to be clickable:

mContactDetailsText.setLinksClickable(true);

您可能还需要设置移动方法:

You might also need movement method set like so:

mContactDetailsText.setMovementMethod(LinkMovementMethod.getInstance())

这篇关于Android Linkify - 可点击的电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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