Public classStringhandleexampleactivityextendsActivity {/**Called when the activity is first created.*/ PrivateTextView TextView; PrivateString TempStr = "Abcd12 My medieval Zx9yu5!f3,"; PrivateStringBuffer SB; PrivateList<integer>list; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); SB=NewStringBuffer (); List=NewArraylist<integer>(); TextView=(TextView) Findviewbyid (R.id.textview); for(inti = 0; I < tempstr.length (); i++) { if(Matcherreg (string.valueof (Tempstr.charat (i))) {List.add (i); }} Spannablestringbuilder Style=NewSpannablestringbuilder (TEMPSTR); for(inti = 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_inclus IVE); //sets the background color of the TextView at the specified positionStyle.setspan (NewForegroundcolorspan (color.red), List.get (i), List.get (i) +1,spannable.span_exclusive_inclusive);//sets the color of text at the specified position} textview.settext (style); } Private BooleanMatcherreg (charsequence c) {String regEx= "[^0-9]"; Pattern P=Pattern.compile (regEx); Matcher m=P.matcher (c.tostring ()); if(M.matches ()) {return false; } return true; } }