標籤:spannablestringbuild android開發 字型
在一行字串中可以做很多事情。
// 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);//設定底線
style.setSpan(new StrikethroughSpan(), 1, 3,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); //刪除線
TextView1.setText(style);
}
:
參考:http://blog.csdn.net/moyunfei1987/article/details/11646835
http://blog.csdn.net/u013493809/article/details/27683415
http://blog.csdn.net/meihua1314/article/details/40986643
android 字元設定之SpannableStringBuilder