use of android.text.style.BackgroundColorSpan in project GwellDemo by dxsdyhm.
the class SensorActivity method setExplain.
private void setExplain() {
String str = "遥控 传感器 特殊传感器 已学习";
int romStart = str.indexOf("遥控");
int romEend = romStart + "遥控".length();
int chStart = str.indexOf("传感器");
int chEend = chStart + "传感器".length();
int spStart = str.indexOf("特殊传感器");
int spEend = spStart + "特殊传感器".length();
int selStart = str.indexOf("已学习");
int selEend = selStart + "已学习".length();
SpannableStringBuilder style = new SpannableStringBuilder(str);
style.setSpan(new BackgroundColorSpan(Color.CYAN), romStart, romEend, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
style.setSpan(new BackgroundColorSpan(Color.GREEN), chStart, chEend, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
style.setSpan(new BackgroundColorSpan(Color.YELLOW), spStart, spEend, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
style.setSpan(new BackgroundColorSpan(Color.RED), selStart, selEend, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tvExplain.setText(style);
}
Aggregations