TextView=(TextView) Findviewbyid (R.id.textview); Spannablestringbuilder Builder=NewSpannablestringbuilder (Textview.gettext (). toString ()); //Foregroundcolorspan is text foreground, Backgroundcolorspan is text background colorForegroundcolorspan Redspan =NewForegroundcolorspan (color.red); Foregroundcolorspan Whitespan=NewForegroundcolorspan (Color.White); Foregroundcolorspan Bluespan=NewForegroundcolorspan (Color.Blue); Foregroundcolorspan GreenSpan=NewForegroundcolorspan (Color.green); Foregroundcolorspan Yellowspan=NewForegroundcolorspan (Color.yellow); Builder.setspan (Redspan,0, 1, spannable.span_exclusive_exclusive); Builder.setspan (Whitespan,1, 2, spannable.span_inclusive_inclusive); Builder.setspan (Bluespan,2, 3, spannable.span_exclusive_exclusive); Builder.setspan (GreenSpan,3, 4, spannable.span_exclusive_exclusive); Builder.setspan (Yellowspan,4,5, spannable.span_exclusive_exclusive); Textview.settext (builder);
android-Modifying the color of some text in a TextView