set Absolute Font Span - Android Graphics

Android examples for Graphics:Spannable Font

Description

set Absolute Font Span

Demo Code


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 w w  w .ja va 2  s .  c o  m
    public static SpannableString setAbsoluteFontSpan(String originStr,
            int size, int start, int end) {

        generateBuilder(originStr);

        SpannableString spannableString = new SpannableString(
                builder.toString());
        AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(size);
        spannableString.setSpan(absoluteSizeSpan, start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }
    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);
        }

    }
}

Related Tutorials