0

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 < > .

4

1 回答 1

1

我不会打扰迭代和解析你的字符串,那是微不足道的。

 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));
于 2013-06-24T07:38:57.840 回答