Android examples for Graphics:Spannable Color
set Foreground Color Span
import android.graphics.Color; import android.graphics.Typeface; import android.text.Spannable; import android.text.SpannableString; import android.text.Spanned; import android.text.style.AbsoluteSizeSpan; import android.text.style.BackgroundColorSpan; import android.text.style.ForegroundColorSpan; import android.text.style.RelativeSizeSpan; import android.text.style.StyleSpan; public class Main{ private static StringBuilder builder; /*from ww w.j a v a2s . c o m*/ public static String setForegroundColorSpan(String originStr, int start, int end) { generateBuilder(originStr); SpannableString spanString = new SpannableString(builder.toString()); ForegroundColorSpan span = new ForegroundColorSpan(Color.BLUE); spanString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanString.toString(); } private static void generateBuilder(String originalText) { builder = new StringBuilder(); for (int i = 0; i < originalText.length(); i++) { String c = String.valueOf(originalText.charAt(i)); builder.append(c); } } }