这个只是做一个笔记,详情见代码:
代码中的注释也有说明。
TextView textView = (TextView) findViewById(R.id.textView1);
SpannableStringBuilder sb = new SpannableStringBuilder("abcdefghijklmnopqrst."); // 包装字体内容
ForegroundColorSpan fcs = new ForegroundColorSpan(getResources().getColor(R.color.yellow_orange)); // 设置字体颜色
StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // 设置字体样式
AbsoluteSizeSpan ass = new AbsoluteSizeSpan(140); // 设置字体大小
sb.setSpan(fcs, 0, 10, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
sb.setSpan(bss, 0, 20, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
sb.setSpan(ass, 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(sb);
运行结果如下: