使Java中的电子邮件正文文本变为粗体,斜体和更大 [英] Make text bold, italic, and bigger for email body in java
问题描述
我发送一封电子邮件,其中包含在整个应用程序中检索到的数据,例如:
I send an E-mail with data retrieved throughout my application like such:
String body = formatEmailBody();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"}); // Set receipient here
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT , body);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
其中 formatEmailBody
创建一个 String
作为邮件正文发送。
Where formatEmailBody
simply creates a String
to be send as body of my email.
但是一个简单的字符串很无聊,我怎么可能
But a simple string is boring, how may I add bold / italic / bigger text?
我尝试了以下操作但没有成功:
I have tried the following to no success:
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<small><p>More content</p></small>")
.toString()));
推荐答案
您是否看过意图,尤其是常量部分,您会在其中看到:
Have you taken a look into Intent, especially the section "Constants", where you see :
EXTRA_HTML_TEXT:
与Intent关联的常量字符串,与ACTION_SEND一起使用,以HTML格式的文本形式替代EXTRA_TEXT。
EXTRA_HTML_TEXT : A constant String that is associated with the Intent, used with ACTION_SEND to supply an alternative to EXTRA_TEXT as HTML formatted text.
但请注意此处:
与Intent关联的常量字符串,用于ACTION_SEND以提供替代EXTRA_TEXT作为HTML格式的文本。请注意,您还必须提供EXTRA_TEXT。
A constant String that is associated with the Intent, used with ACTION_SEND to supply an alternative to EXTRA_TEXT as HTML formatted text. Note that you must also supply EXTRA_TEXT.
因此,类似下面的内容可以提高html内容正确显示的几率:-
So something like the below should improve the odds of the html content being displayed correctly :-
i.setType("text/html");
i.putExtra(Intent.EXTRA_HTML_TEXT, htmlText);
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(htmlText));
这篇关于使Java中的电子邮件正文文本变为粗体,斜体和更大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!