Android character setting: SpannableStringBuilder and androidbuilder
You can do a lot in a line of strings.
// 1 and 3 indicate the start and end positions of the font.
Private void settext ()
{
SpannableStringBuilder style = new SpannableStringBuilder ("Welcome to golden sun ");
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); // set the font color
Style. setSpan (new StyleSpan (Typeface. BOLD), 1, 3, Spannable. SPAN_EXCLUSIVE_EXCLUSIVE); // set the font width
Style. setSpan (new AbsoluteSizeSpan (30, true), 1, 3, Spannable. SPAN_EXCLUSIVE_EXCLUSIVE); // set the font size
CharacterStyle span = new UnderlineSpan ();
Style. setSpan (span, 1, 3, Spannable. SPAN_EXCLUSIVE_EXCLUSIVE); // set the underline
Style. setSpan (new StrikethroughSpan (), 1, 3, Spanned. SPAN_EXCLUSIVE_EXCLUSIVE); // strikethrough
TextView1.setText (style );
}
:
Reference: http://blog.csdn.net/moyunfei1987/article/details/11646835
Http://blog.csdn.net/u013493809/article/details/27683415
Http://blog.csdn.net/meihua1314/article/details/40986643