码迷,mamicode.com
首页 > 移动开发 > 详细

Android中TextView中的文字设置为不同颜色

时间:2016-04-05 00:38:04      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

questionDesTextView=(TextView)findViewById(R.id.question_des);
        SpannableStringBuilder builder = new SpannableStringBuilder(questionDesTextView.getText().toString());
        //ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色
        ForegroundColorSpan blackSpan = new ForegroundColorSpan(Color.BLACK);
        ForegroundColorSpan graySpan=new ForegroundColorSpan(Color.GRAY);

//第二个参数是开始的下标,第三个参数是结束的下标 builder.setSpan(blackSpan,
0,4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(graySpan,4,9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); questionDesTextView.setText(builder);

 

Android中TextView中的文字设置为不同颜色

标签:

原文地址:http://www.cnblogs.com/rainhome/p/5353334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!