<span style="white-space:pre"> </span>TextView tv = (TextView)findViewById(R.id.tv );
//将文本内容封装到SpannableString中
SpannableString spannableString = new SpannableString("我是文本内容");
//BackgroundColorSpan 并制定文本颜色为红色
BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(Color.GREEN);
//调用setSpan方法设置文本
spannableString.setSpan(backgroundColorSpan,0,6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//设置文本
tv.setText(spannableString);
转载请注明原文地址: https://ju.6miu.com/read-1295367.html