Spannable 对文字的编辑减少TextView的拼接并且达到改变一串字符中的部分文字的字体颜色,背景颜色,字体大小,样式 增加文字的超链接。
如 把部分字体改成红色:
SpannableString amountS=new SpannableString(amount);
amountS.setSpan(new ForegroundColorSpan(Color.RED), amount.indexOf(orderInfo.PayMoney+""), amount.indexOf("元")+1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
具体主要介绍setSpan()中的what和flags参数: