Android examples for android.text:SpannableString
Create SpannableString and set Style
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.StrikethroughSpan; import android.text.style.StyleSpan; import android.text.style.SubscriptSpan; import android.text.style.SuperscriptSpan; import android.text.style.TypefaceSpan; import android.text.style.UnderlineSpan; public class Main{ /**//w ww .ja va2 s .co m * @param source * @param start * @param end * @param style * Typeface.NORMAL,Typeface.BOLD, * Typeface.ITALIC,Typeface.BOLD_ITALIC * @return */ public static SpannableString setStyle(CharSequence source, int start, int end, int style) { if (source == null) { return null; } SpannableString sp = new SpannableString(source); sp.setSpan(new StyleSpan(style), start, end, FLAGS); return sp; } }