在一行字符串中可以做很多事情。
// 1和3代表设置字体的开始位置和结束位置。
private void settext(){SpannableStringBuilder style=new SpannableStringBuilder("欢迎使用金太阳"); style.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.blue)),4,6,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);style.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.red)),1,3,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//设定字体颜色style.setSpan(new StyleSpan(Typeface.BOLD),1,3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //设定字体粗细style.setSpan(new AbsoluteSizeSpan(30,true),1, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //设定字体大小CharacterStyle span=new UnderlineSpan(); style.setSpan(span, 1, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//设置下划线
,3,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); //删除线TextView1.setText(style);}
效果图:
参考:
,而消极的人则在每个机会都看到某种忧患。