//部分文字改变颜色
//ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色
ForegroundColorSpan redSpan = new ForegroundColorSpan(getResources().getColor(R.color.text_red));
ForegroundColorSpan graySpan = new ForegroundColorSpan(getResources().getColor(R.color.text_gray));
mTextView.setText("灰色红色");
//这里注意一定要先给textview赋值
SpannableStringBuilder builder = new SpannableStringBuilder(mTextView.getText().toString());
//为不同位置字符串设置不同颜色
builder.setSpan(graySpan, 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(redSpan, 2, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//最后为textview赋值
mTextView.setText(builder); //部分文