Reputation: 27
I found only how to change the color of a word in a sentence or how to change the color of the sentence. Can any body tell me how to color all words between two specific notation. For ex: My name is < pravind kumar > . i have to change the color of word pravind kumar. For that i want to traverse every alphabet and change color of every alphabet between < > .
Upvotes: 0
Views: 232
Reputation: 4650
I am not going to bother iterating and parsing your string thats trivial.
SpannableString span1 = new SpannableString("pravind ");
SpannableString span2 = new SpannableString("kumar");
span1 .setSpan(new ForegroundColorSpan(Color.BLUE), 5, 13,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span2.setSpan(new ForegroundColorSpan(Color.RED), 5, 13,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextView.setText(TextUtils.concat(span1," " ,span2));
Upvotes: 1