The example in this article describes the way that Android programming implements some of the color changes in TextView. Share to everyone for your reference, specific as follows:
The public class Stringhandleexampleactivity extends activity {/** called the ' when the ' is ' the ' activity ' is the ' the '. * Private
TextView TextView;
Private String TempStr = "Abcd12 My medieval Zx9yu5!f3,";
Private StringBuffer SB;
Private list<integer> List;
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
SB = new StringBuffer ();
List = new arraylist<integer> ();
TextView = (TextView) Findviewbyid (R.id.textview); for (int i = 0; i < tempstr.length (); i++) {if (Matcherreg (string.valueof (Tempstr.charat (i))) {List.ad
D (i);
} spannablestringbuilder style=new Spannablestringbuilder (TEMPSTR);
for (int i = 0; i < list.size (); i++) {System.out.println (List.get (i) + ","); Style.setspan (New Backgroundcolorspan (color.red), List.get (i), List.get (i) +1,spannable.span_exclusive_inclusive ); Sets the background color of the TextView at the specified location Style.setspan (new FOregroundcolorspan (color.red), List.get (i), List.get (i) +1,spannable.span_exclusive_inclusive);
Sets the color of the specified location text} textview.settext (style);
Private Boolean Matcherreg (Charsequence c) {String regex= ' [^0-9] ';
Pattern p = pattern.compile (regEx);
Matcher m = P.matcher (C.tostring ());
if (M.matches ()) {return false;
return true;
}
}
I hope this article will help you with your Android programming.