[英]How to change the color the words between two specific words in a sentence
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 > .
例如:我叫<pravind kumar>。 i have to change the color of word pravind kumar.
我必须更改pravind kumar一词的颜色。 For that i want to traverse every alphabet and change color of every alphabet between < > .
为此,我想遍历每个字母并在<>之间更改每个字母的颜色。
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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.