get Decorated Text as SpannableString - Android Graphics

Android examples for Graphics:Spannable

Description

get Decorated Text as SpannableString

Demo Code


//package com.java2s;

import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.style.StyleSpan;

public class Main {
    public static SpannableString getDecoratedText(CharSequence text,
            boolean bold, boolean italic) {
        SpannableString s = new SpannableString(text);
        if (bold && italic) {
            s.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, s.length(), 0);
        } else if (bold) {
            s.setSpan(new StyleSpan(Typeface.BOLD), 0, s.length(), 0);
        } else if (italic) {
            s.setSpan(new StyleSpan(Typeface.ITALIC), 0, s.length(), 0);
        }//from  ww w  . j  a va  2 s  . c  o m

        return s;
    }
}

Related Tutorials