TextView textView = (TextView)findViewById(R.id.textview);
//方法一:
textView.setText(Html.fromHtml("<font color=\"#ff0000\">红色</font>其它颜色"));
//方法二:
String text = "获得银宝箱!";
SpannableStringBuilder style=new SpannableStringBuilder(text);
//设置指定位置textview的背景颜色
style.setSpan(new BackgroundColorSpan(Color.RED),2,5,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
//设置指定位置文字的颜色
style.setSpan(new ForegroundColorSpan(Color.RED),0,2,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
textView.setText(style);
android textview改变部分文字的颜色
最新推荐文章于 2024-07-13 23:11:02 发布