如何添加电子邮件链接到布局xml,Android [英] How to add email link to layout xml, Android

查看:231
本文介绍了如何添加电子邮件链接到布局xml,Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xml文件,用于显示我的应用程序中的关于AlertDialog。
我能够从文本资源中获取文本区域,文本右侧有图像。
现在我需要添加支持电子邮件和可能的家庭网站地址到文本。但是我需要它可点击。所以点击电子邮件将发送一封电子邮件,点击网站将打开浏览器。
如何添加这些链接的文本?

 <?xml version =1.0encoding =utf- 8\" >?; 
< LinearLayout
xmlns:android =http://schemas.android.com/apk/res/android
android:layout_width =fill_parent
android:layout_height =fill_parentandroid:weightSum =1android:orientation =horizo​​ntalandroid:baselineAligned =true>
< TextView android:text =@ string / AboutStringandroid:layout_gravity =center_horizo​​ntalandroid:id =@ + id / textView1android:layout_height =173dpandroid:layout_width =wrap_contentandroid :textAppearance =?android:attr / textAppearanceMediumandroid:drawableRight =@ drawable / explain>< / TextView>
< / LinearLayout>

编辑:我选择的解决方案:

 查看layout = inflater.inflate(R.layout.about,null); 
模式p = Pattern.compile(somemail@domain.net);
String Scheme =mailto:somemail@domain.net;
Linkify.addLinks((TextView)layout.findViewById(R.id.textView1),p,Scheme);


解决方案

查看的文章是android-developers.blogspot.com/2008/03/linkify-your-text.htmlrel =nofollow。您需要链接您的文本。


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>

EDIT: The solution I chose:

                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);

解决方案

Check out this article. You need to linkify your text.

这篇关于如何添加电子邮件链接到布局xml,Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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