什么都不说,上代码:
public class StringInterceptionUtil {
/**
* 字符串截取变红
*
* @param string3 你要变色的字符,可为null
* @param string2 你要变色的字符
* @param string 整个字符串
* @param numtext
*/
public static void StringInterceptionChangeRed(TextView numtext,
String string, String string2, String string3) {
int fstart = string.indexOf(string2);
int fend = fstart + string2.length();
SpannableStringBuilder style = new SpannableStringBuilder(string);
if(!"".equals(string3)&&string3!=null){
int bstart=string.indexOf(string3);
int bend=bstart+string3.length();
style.setSpan(new ForegroundColorSpan(Color.RED), bstart, bend,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
style.setSpan(new ForegroundColorSpan(Color.RED), fstart, fend,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
numtext.setText(style);
}
}