[b][color=indigo]TextView字体改变颜色用法[/color][/b]
如下图:
[img]http://dl.iteye.com/upload/attachment/0084/2690/3165b2c2-1bae-3f47-8351-d64453a7f917.png[/img]
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_view);
TextView tv = (TextView)findViewById(R.id.tv);
String str="怎么改变文字呢怎么改变文字呢怎么改变文字呢怎么改变文字呢怎么改变文字呢";
SpannableStringBuilder style = new SpannableStringBuilder(str);
style.setSpan(new ForegroundColorSpan(Color.RED), 0, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
style.setSpan(new ForegroundColorSpan(Color.GREEN), 10, 15, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
style.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(style);
}
如下图:
[img]http://dl.iteye.com/upload/attachment/0084/2690/3165b2c2-1bae-3f47-8351-d64453a7f917.png[/img]