这个只是做一个笔记,详情见代码:
代码中的注释也有说明。
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);运行结果如下:
本文介绍了如何在Android应用中利用SpannableStringBuilder动态修改TextView文本的样式、颜色、大小等属性,包括使用ForegroundColorSpan、StyleSpan、AbsoluteSizeSpan等Span实现文本样式变化。
3126

被折叠的 条评论
为什么被折叠?



