字符串显示不同的颜色的方法

1. 使用ColorStateList

ColorStateList redColors = ColorStateList.valueOf(0Xffff0000);

SpannableStringBuilder spanBuilder = spanBuilder.setSpan(new TextAppearenceSpan(null, 0, 0, redColors, null),4, 10,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);

2. 使用Html

String temp = “name:
hello<b>activeBalance</b>”;

Html.fromHtml(temp);

你可能感兴趣的:(Android代码实现)