0

I need to add some text in a textview with some text with red color and some are black color with a specific formatting

Spannable wordtoSpan = new SpannableString(temp.substring(start, i));
wordtoSpan.setSpan(new ForegroundColorSpan(Color.RED), 0, wordtoSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//failedToSolve.append(wordtoSpan); // was working when I used no formatting
failedToSolve.append(String.format("%7s", wordtoSpan)); // coloring is not working after I apply String.format on it

I know I am formatting Spannable object with String class method. Is there any alternatives? How can I do the formatting and coloring together? I used HTML tag but no effects. Thanks in advance.

Kaidul
  • 15,409
  • 15
  • 81
  • 150

1 Answers1

1

Is there any alternatives?

Call String.format() first, then create the SpannableString from the result and apply the ForegroundColorSpan.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491