String amount = Util.unitConversion(borrowInfo.getAmount());
//文字颜色
ColorStateList redColors = ColorStateList.valueOf(getResources()
.getColor(R.color.title_bar_bg_color));
//要设置的文字
SpannableStringBuilder spanBuilder = new SpannableStringBuilder(amount);
//第一个参数设置字体大小,第二个和第三个参数是从字符串的哪个开始到哪个结束
//TextAppearanceSpan第二个参数设置字体,0为默认,第三个是字体大小(单位px),第四个是字体颜色
spanBuilder.setSpan(new TextAppearanceSpan(null, 0, 22,redColors, null),
amount.length() - 1, amount.length(),Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
borrowAmountTextView.setText(spanBuilder);//最后显示到TextView上
//只设置部分字体颜色
String text = getResources().getString(R.string.financinged_text,
borrowInfo.getProgress()) + "%";
SpannableString sp = new SpannableString(text);
sp.setSpan(new ForegroundColorSpan(getResources().getColor(
R.color.orange_text_color)), 3, text.length() - 1,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
investedTextView.setText(sp);
转载于:https://my.oschina.net/meetthebetteryour/blog/607546