Change the color of text (line) when sending an email message

I am trying to change the color of text (line) when I output it by 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[]{" payrolldirectgib@gmail.com "}); 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 want the string "appdata" to appear in red in the email field.

Can this be done and how?

Thanks in advance.

+6
source share
2 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 took the simplest method, and I included it in my code as follows:

 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[]{" payrolldirectgib@gmail.com "}); 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); 

Hope my answer helps you.

+3
source

Use the code as shown below:

 emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<font color='#FE2B3C'>"+appdata+"</font>"+sep+"Please send this email.")); 
0
source

Source: https://habr.com/ru/post/987922/


All Articles