0
String records = "<font color='red'>"+edittext.getText().toString()+"</font>.";

textView.setText("Total Records to be SYNC : "+Html.fromHtml(records) +"\nDo you want sync all records...!", TextView.BufferType.SPANNABLE);

here its not displayed in red color

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
veeraprasad
  • 61
  • 1
  • 6
  • Recently, I have had to work with text that was bold in between or different colored. I found SpannableStringBuilder to be really really helpful and easy. Check this: http://stackoverflow.com/questions/4897349/android-coloring-part-of-a-string-using-textview-settext – Adeel Shahzad Dec 16 '16 at 07:39
  • seems people have answered the question even without reading – Charuක Dec 16 '16 at 07:44

4 Answers4

0

I think you are doing it in wrong way. Check out this answer, it may help you.

How to set the text color of TextView in code?

Community
  • 1
  • 1
0

A variation using just standard color code:

android:textColor="#ff0000"

Add it in XML of TEXTVIEW

or use

textview.setTextColor(color);
Athul
  • 801
  • 7
  • 16
0
SpannableStringBuilder builder = new SpannableStringBuilder();

String red = edittext.getText().toString();
SpannableString redSpannable= new SpannableString(red);
redSpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, red.length(), 0);
builder.append(redSpannable);

mTextView.setText("Total Records to be SYNC : "+builder+"\nDo you want sync all records...!", BufferType.SPANNABLE);
Nirmal Shethwala
  • 268
  • 1
  • 15
0

You can do with following code, I have tested and It's working perfect.

String value1 = "Total Records to be SYNC : ";
String value2 = "\nDo you want sync all records...!";
String valueFromEdittext = edittext.getText().toString();
String finalValue = value1 + valueFromEdittext + value2;
Spannable WordtoSpan = new SpannableString(finalValue);
WordtoSpan.setSpan(new ForegroundColorSpan(Color.RED), value1.length(), (value1 + valueFromEdittext).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextView.setText(WordtoSpan);
Rajesh Panchal
  • 1,140
  • 3
  • 20
  • 39