Mic*_*son 5 android textview android-phone-call
我有一个包含电子邮件和电话号码的文本视图。我想要的效果是,当用户点击电子邮件时,它会打开默认的电子邮件应用程序,当用户点击电话号码时,应用程序会将其拉到拨号器中。使用以下代码:
XML:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/careers_guidance"
android:id="@+id/careers_guidance_text"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="5dp"
android:linksClickable="true"
android:textColorLink="#0000EE"
android:autoLink="all"/>
Run Code Online (Sandbox Code Playgroud)
爪哇:
careersGuidance = view.findViewById(R.id.careers_guidance_text);
careersGuidance.setText(Html.fromHtml("<p>Help with choosing the right course and with thinking about where this might take you in the future.</p>" +
"<p>Tel: <a href=\"tel:01274433043\">01274 433043</a></p>Email: <a href=\"mailto:careers@bradfordcollege.ac.uk\">careers@bradfordcollege.ac.uk</a>"));
Run Code Online (Sandbox Code Playgroud)
当我运行我的应用程序时,只有电子邮件可点击并按我希望的方式工作,电话号码不可点击或突出显示。
但是,我注意到如果我从 setText java 代码中删除电子邮件地址并运行该应用程序。电话号码变成蓝色并带有下划线,好像可以点击一样,但是当我点击它时,没有任何反应。
我怎样才能让它工作?
此外,我在清单文件和模拟器设备上授予了 CALL_PHONE 权限。
从电子邮件 (.ac.uk) 来看,我猜您来自英国。您只需添加您所在国家/地区的电话号码前缀来替换 0,即 +44。而且您不需要使用Html.fromHtml.
careersGuidance.setText("Help with choosing the right course and with thinking about where this might take you in the future.\n\nTel: +441274433043\n\nEmail: careers@bradfordcollege.ac.uk");
Run Code Online (Sandbox Code Playgroud)
在你的xml中,你只需要这个属性
android:autoLink="all"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2913 次 |
| 最近记录: |