简体   繁体   English

如何使 XML 字符串资源 email 可点击 TextView 上的预定义主题和正文

[英]How to make XML string resource email clickable with predefined Subject and Body on TextView

Namaste to all,向所有人合十礼

I am trying to achieve a solution where on click of email id in strings XML containing HTML tags we should open Intent Chooser of email apps available in the system, then in the email compose screen mailTo , subject & the body should be populated.我正在尝试实现一个解决方案,在单击包含 HTML 标签的字符串 XML 中的 email id 时,我们应该打开系统中可用的 email 应用程序的 Intent Chooser,然后在 email 撰写屏幕mailTo中,应填充主题正文

 to - recipient@xyz.com subject - xyz.... body - xyz.....

I have tried using android:autoLink="email" attribute, it is making the email clickable but it only pre-populates the recipient's email id and nothing else.我试过使用android:autoLink="email"属性,它使 email 可点击,但它只预填充收件人的 email id,仅此而已。

Is there any other way around to achieve the required solution, without using a third-party library?有没有其他方法可以在不使用第三方库的情况下实现所需的解决方案?

You have to add a link as follow:您必须添加一个链接,如下所示:

mailto:recipient@xyz.com?subject=xyz subject&body=xyz body

This link will open an Intent for Mail application and will contain a prefill subject and body.此链接将打开 Intent for Mail 应用程序并将包含预填主题和正文。 (Ref: https://css-tricks.com/snippets/html/mailto-links/ ) (参考: https://css-tricks.com/snippets/html/mailto-links/

You can have a string as follow:你可以有一个字符串如下:

<string name="link_str"><a href="mailto:recipient@xyz.com?subject=xyz subject&body=xyz body">Send email</a>  </string>

And then make TextView linkable as specified in https://stackoverflow.com/a/49694038/5309486然后按照https://stackoverflow.com/a/49694038/5309486中的规定使 TextView 可链接

Namaste to all,向所有人合十礼,

Below is the working solution, without using the android:autoLink="email" attribute.下面是工作解决方案,不使用android:autoLink="email"属性。

strings.xml字符串.xml

 <string name="str_email_included">Mail us at - &lt;br/> &lt;a href=\'mailto:hello@xyz.com?subject=Subject1&amp;body=Body1\'>hello@xyz.com&lt;/a></string>

Java Java

 textView.setText(Html.fromHtml(getString(R.string.str_email_included))); textView.setMovementMethod(LinkMovementMethod.getInstance());

Kotlin Kotlin

 textView.text = HtmlCompat.fromHtml(getString(R.string.str_email_included), HtmlCompat.FROM_HTML_MODE_LEGACY) textView.movementMethod = LinkMovementMethod.getInstance()

The above movementMethod does the job, so onClick of email id, Intent Chooser will open and the mailTo, subject & body get pre-populated as required.上面的movementMethod完成了工作,所以 email id 的 onClick,Intent Chooser 将打开,并且 mailTo、subject 和 body 会根据需要预先填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使TextView中的一个单词带有可点击字符串中的长文本? - How to make one word in a TextView with a long text from a string clickable? 我将如何创建用于发送电子邮件的函数,其参数设置为String from,String to,String Subject和String body? - How would I create the function for sending an email with the parameters set as String from, String to, String Subject, and String body? textview clickable without xml - textview clickable without xml 使popupWindow TextView可点击? - make popupWindow TextView clickable? 使用单个TextView进行可点击的循环? - Make a clickable loop with a single TextView? 如何在 TextView 中显示带有参数的 HTML 字符串资源? - How to display HTML string resource with parameters in TextView? 如何在不使用TextView的情况下使AlertDialog中的链接可单击? - How I can make links clickable in an AlertDialog without using a TextView? 如何在Android中制作“可点击”行并在TextView中突出显示行和文本 - How to make a “clickable” row in Android and highlight the row and texts in TextView 如何在TextView中制作以http或www开头的可点击链接 - How to make clickable links that starts with http or www in TextView 创建包含收件人、主题、正文和附件的电子邮件 - Create email with recipient, subject, body AND attachment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM