问题描述
我有一个 xml 文件,用于在我的应用程序中显示 About AlertDialog.我能够从文本资源中获得一个文本区域,以及文本右侧的图像.现在我需要在文本中添加支持电子邮件和可能的家庭网站地址.但我需要它是可点击的.因此,单击电子邮件将发送电子邮件,单击网站将打开浏览器.如何添加这些链接文本?
I have an xml file I use to show the About AlertDialog in my App.I was able to have an area of text from a text resource, and an image to the right of the text.Now I need to add the support email and possible home website address to the text. But I need it to be clickable. So clicking on the email will send an email and clicking on the website will open the browser.How do I add those linked text?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1" android:orientation="horizontal" android:baselineAligned="true">
<TextView android:text="@string/AboutString" android:layout_gravity="center_horizontal" android:id="@+id/textView1" android:layout_height="173dp" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:drawableRight="@drawable/explain"></TextView>
</LinearLayout>
我选择的解决方案:
View layout = inflater.inflate(R.layout.about, null);
Pattern p = Pattern.compile("somemail@domain.net");
String Scheme = "mailto:somemail@domain.net";
Linkify.addLinks((TextView)layout.findViewById(R.id.textView1), p, Scheme);
推荐答案
您需要 链接您的文字.以下是该文章中的一个示例,展示了如何在找到 WikiWord 时添加链接:
You need to linkify your text. Here is an example from that article showing how to add links when a WikiWord is found:
Pattern wikiWordMatcher = Pattern.compile("\b[A-Z]+[a-z0-9]+[A-Z][A-Za-z0-9]+\b");
String wikiViewURL = "content://com.google.android.wikinotes.db.wikinotes/wikinotes/";
Linkify.addLinks(noteView, wikiWordMatcher, wikiViewURL);
这篇关于如何将电子邮件链接添加到布局 xml,Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!