首页 > 移动平台 > 详细

android-修改TextView中部分文字的颜色

时间:2014-08-23 16:47:51      阅读:222      评论:0      收藏:0      [点我收藏+]

bubuko.com,布布扣

 

 
textView = (TextView) findViewById(R.id.textview);  
SpannableStringBuilder builder = new SpannableStringBuilder(textView.getText().toString());  
  
//ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色  
ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);  
ForegroundColorSpan whiteSpan = new ForegroundColorSpan(Color.WHITE);  
ForegroundColorSpan blueSpan = new ForegroundColorSpan(Color.BLUE);  
ForegroundColorSpan greenSpan = new ForegroundColorSpan(Color.GREEN);  
ForegroundColorSpan yellowSpan = new ForegroundColorSpan(Color.YELLOW);  
  
  
  
builder.setSpan(redSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);  
builder.setSpan(whiteSpan, 1, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE);  
builder.setSpan(blueSpan, 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);  
builder.setSpan(greenSpan, 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);  
builder.setSpan(yellowSpan, 4,5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);  
  
textView.setText(builder);  

 

 

 

android-修改TextView中部分文字的颜色

原文:http://www.cnblogs.com/niray/p/3931418.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!