android同一个TextView设置不同颜色字体

 1     SpannableStringBuilder style = new SpannableStringBuilder(str);
 2             style.setSpan(
 3                     new ForegroundColorSpan(getResources().getColor(
 4                             R.color.tab_sel_color)), 0, t1.length() - 1,
 5                     Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
 6             style.setSpan(
 7                     new ForegroundColorSpan(getResources().getColor(
 8                             R.color.tab_sel_color)), t1.length() + 3,
 9                     t1.length() + 3 + t2.length(),
10                     Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
11             mCarGuidancePrice.setText(style);

 

posted on 2015-04-07 10:20  彪biao  阅读(662)  评论(0编辑  收藏  举报

导航