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yJiYmdO3cmJyefPXvWyKCmsbGxS5cubd68ed++fX7vyf+mBTMAIaS6utrvqABCiMfjCa5qLan6qSAM4kdZpoQle2cE4rd3Gd/2oLPuUTQJ7pYaGe9FiUyo+FEoFAol4qDiR6FQKJSIg4ofhUKhUCIOKn4UCoVCiTio+FEoFAol4qDiR6FQKJSIg4ofhUKhUCIOKn4UCoVCiTio+FEoFAol4qDiR6FQKJSIg4ofhUKhUCIOKn4UCoVCiTio+FEoFAol4qDiR6FQKJSIg4ofhUKhUCIOKn4UCoVCiTio+FEoFAol4qDiR6FQKJSIg4ofhUKhUCKO/wcafpHrVFoWpQAAAABJRU5ErkJggg==" alt="" />
/**
* @param textView
* @param positions 变色的位置
* @param colors 多个颜色值,数量和positions的数量可以不一致,如果颜色值比位置值少,则是交叉来使用的
* @描述 设置一个textivew显示多种颜色
* @作者 tll
* @时间 2016/11/11 10:37
*/
public static void setMultipleColor(TextView textView, List<Integer> positions, Integer... colors) {
if (isEmpty(positions)) {
return;
}
SpannableStringBuilder builder = new SpannableStringBuilder(textView.getText().toString());
for (int i = 0; i < positions.size(); i++) {
ForegroundColorSpan span = new ForegroundColorSpan(colors[i % colors.length]);
if (i == 0) {
builder.setSpan(span, 0, positions.get(i), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
builder.setSpan(span, positions.get(i - 1), positions.get(i), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
textView.setText(builder);
} 使用方法:
text = (TextView) findViewById(R.id.text);
List<Integer> positions = new ArrayList<>();
positions.add(4);
positions.add(6);
positions.add(11);
positions.add(13);
positions.add(text.getText().toString().length());
setMultipleColor(text, positions, getResources().getColor(R.color.color_353535), getResources().getColor(R.color.color_f67067));