1.textview改变部分字体颜色
SpannableStringBuilder sb = new SpannableStringBuilder();
sb.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.rgbfcff24)), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); //设置前景色
textview.setText(sb);
2.textview设置下划线:
UnderlineSpan underlineSpan = new UnderlineSpan();
int start = sb.length() - 4;
int end = sb.length();
sb.setSpan(underlineSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
3.对设置下划线部分的字体单独点击onclick监听
int flags = sb.getSpanFlags(underlineSpan);
ClickableSpan clickableSpan = new ClickableSpan(){
@Override
public void onClick(View widget) {
}
};
sb.setSpan(clickableSpan, start, end, flags);
4.textview有添加超链接,前景色,背景色,下划线,横线,各种风格的span。
具体不举例子了。