android-修改TextView中部分文字的颜色
2014-03-31 09:51
441 查看
转载于:http://blog.csdn.net/centralperk/article/details/8674599
[java] view
plaincopy
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);
[java] view
plaincopy
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中部分文字的颜色
- 『ANDROID』android-修改TextView中部分文字的颜色
- android-修改TextView中部分文字的颜色
- android 修改TextView中部分文字的颜色
- android-修改TextView中部分文字的颜色
- android-修改TextView中部分文字的颜色
- android-修改TextView中部分文字的颜色
- Android-修改TextView中部分文字的颜色
- android-修改TextView中部分文字的颜色
- 【转】android-修改TextView中部分文字的颜色
- android 各种 span的生成 如:修改TextView中部分文字的颜色 ,生成图片span
- android-代码修改TextView中部分某段文字的颜色
- android-修改TextView中部分文字的颜色
- android-修改TextView中部分文字的颜色
- android-修改TextView中部分文字的颜色
- android-修改TextView中部分文字的颜色
- android-修改TextView中部分文字的颜色
- android-修改TextView中部分文字的颜色
- android textview改变部分文字的颜色和string.xml中文字的替换
- android--设置TextView部分文字的颜色和背景(高亮显示)