Use of Textappearancespan in Android
Posted on April 17, 2011
How do you want to have rich style settings for your text in Word like in Android?
Textappearancespan can help you achieve this goal.
Here is an example:
//format "Hello"Spannablestringbuilder Builder=NewSpannablestringbuilder (); String str1="Hello"; Spannablestring SS1=Newspannablestring (str1);intlen=str1.length (); Ss1.setspan (NewTextappearancespan (activity, Util.gettextappearanceresource (settings.theme,android). R.style.textappearance_large)),0, len,spanned.span_exclusive_exclusive);//set the world formatString str2="World";intLen2=str2.length (); Spannablestring SS2=Newspannablestring (STR2); Foregroundcolorspan ColSpan=NewForegroundcolorspan ((Context.getresources (). GetColor (r.color.red))); Ss2.setspan (ColSpan,0, Len2, spanned.span_exclusive_exclusive), Builder.append (SS1). Append (SS2). Append ("!"); Titleview.settext (builder);
Among them, "hello" constructs the style through the style textappearanceresource, "World" through the Foregroundcolorspan to set the text format.
This is the application of Textappearancespan, please leave a message.
Source Address: http://androidfuture.com/blog/?p=189