format string by style using SpannableString - Android android.text

Android examples for android.text:SpannableString

Description

format string by style using SpannableString

Demo Code

import android.content.Context;
import android.text.SpannableString;
import android.text.style.TextAppearanceSpan;

public class Main{

    public static SpannableString format(Context context, String text,
            int style) {
        SpannableString spannableString = new SpannableString(text);
        spannableString.setSpan(new TextAppearanceSpan(context, style), 0,
                text.length(), 0);//  ww w. j a v a 2  s  . c  om
        return spannableString;
    }

}

Related Tutorials