Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the colour of text (string) when sending an email

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.

like image 803
Chris Music Avatar asked May 26 '15 11:05

Chris Music


People also ask

How do I change the color of my text in my email?

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.

Why does my font color change when I send an email?

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.

How do you change the color of a string?

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.


1 Answers

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.

like image 140
Thomas Vos Avatar answered Oct 04 '22 11:10

Thomas Vos