Android使电话号码可点击,自动检测 [英] Android make phone numbers clickable, autodetect
问题描述
当我在网站上使用 Android 并阅读电子邮件时,我注意到我可以点击地址加载到谷歌地图中,或点击电话号码拨打电话,或点击电子邮件并发送电子邮件.
When I am using android on websites and reading emails, I notice that I can click on addresses to load into google maps, or click on phone numbers to call, or click on emails and send an email.
网络上的这些元素以多种方式格式化,因此有一些内置函数可以检测这些类型的东西.
These elements on the web are formatted in a variety of ways, so there is some built in function that detects these sort of things.
如何在我的应用中允许此操作?我有一个页面以纯文本形式显示联系信息,我希望用户能够点击.
How do I allow this within my app? I have a page which displays contact information in plain text and I would like the user to just be able to click.
我是否绝对需要为每个文本视图创建点击监听器,或者是否有我只需要启用的系统功能?
Do I Absolutely need to create clicklisteners for each textview or is there a system function I just need to enable?
推荐答案
Android 有一个专门用于此目的的实用程序:链接
Android has a utility expressly for this purpose: Linkify
TextView noteView = (TextView) findViewById(R.id.noteview);
noteView.setText(someContent);
Linkify.addLinks(noteView, Linkify.ALL);
另见:https://android-developers.googleblog.com/2008/03/linkify-your-text.html
这篇关于Android使电话号码可点击,自动检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!