当我将文本(字符串)输出到电子邮件时,我试图更改它的颜色。我的代码是:
String appdata = "%" + txtFromSpinner + location.getText() + "%" + date.getText()+ "%" + start.getText() + "%" + finish.getText() + "%" + lunch.getText() + "%" + details.getText();
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected] /cdn-cgi/l/email-protection"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Timesheet/Parte de horas");
emailIntent.putExtra(Intent.EXTRA_TEXT, appdata +sep+ "Please send this email."+sep+ "Your timesheet details are included in it."+sep+ "Thank you."+sep+ "Regards,"+sep+ "Admin Department."+sep+ "Payroll Direct.");
emailIntent.setType("message/rfc822");
startActivity(emailIntent);
我希望字符串“appdata”在电子邮件消息框中显示为红色。
这可以做到吗?如何做到?
先感谢您。
有两种方法
Method 1
SpannableStringBuilder builder = new SpannableStringBuilder();
SpannableString redSpannable= new SpannableString(appdata);
redSpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, appdata.length(), 0);
builder.append(redSpannable);
Method 2
appdata_in_red = Html.fromHtml("<font color=#ff0000>" + appdate + "</font>");
我采用了最简单的方法,并将其集成到您的代码中,如下所示:
String appdata = "%" + txtFromSpinner + location.getText() + "%" + date.getText()+ "%" + start.getText() + "%" + finish.getText() + "%" + lunch.getText() + "%" + details.getText();
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected] /cdn-cgi/l/email-protection"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Timesheet/Parte de horas");
//this line below
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<font color=#ff0000>" + appdata + "</font>") +sep+ "Please send this email."+sep+ "Your timesheet details are included in it."+sep+ "Thank you."+sep+ "Regards,"+sep+ "Admin Department."+sep+ "Payroll Direct.");
emailIntent.setType("message/rfc822");
startActivity(emailIntent);
希望我的回答对您有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)