/**
* 设置字符串中的数字显示红色
* @param str
*/
public static void setNumberTextColor(String str,TextView textView,Context c,int resourcesID){
char[] s = str.toCharArray();
SpannableString ss = new SpannableString(str);
for (int i = 0; i < s.length; i++){
if (isNum(String.valueOf(s[i]))){
ss.setSpan(new ForegroundColorSpan(c.getResources().getColor(resourcesID)), i, i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
textView.setText(ss);
}
/**
* 判断是否是数字
* @param str
* @return
*/
private static boolean isNum(String str) {
try {
new BigDecimal(str);
return true;
} catch (Exception e) {
return false;
}
}