I'm trying to change the colour of the text (a string) when I output it to an email. My code is:
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]"});
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);
I would like the string "appdata" to appear in red when in the email message box.
Can this be done and how?
Thank you in advance.
Under Compose messages, choose Stationery and Fonts. On the Personal Stationery tab, under New mail messages or Replying or forwarding messages, choose Font. In the Font box, choose the font, style, size, and color that you want to use. You can see a preview of your changes as you make them.
For emails created in plain text format, Outlook uses the default ASCII text font, which is also black. For emails that you reply to or forward, the default font color is usually dark blue. You can apply different styles to HTML and rich text format emails to change the font style and font color.
textView. setText(Html. fromHtml(s)); And find the color code for red and replace it with, color=#00aeef for the color you want, say red.
There are two methods
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>");
I have taken the simplest method and I integrated it into your code like this:
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]"});
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);
I hope my answer will help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With