get Custom Font Text - Android Graphics

Android examples for Graphics:Font

Description

get Custom Font Text

Demo Code

/**/*from  w  w  w. ja  v  a  2 s .  c o m*/
 * Copyright (c) 2015 Bookmate.
 * All Rights Reserved.
 * <p/>
 * Author: Dmitry Gordeev <netimen@dreamindustries.co>
 * Date:   02.07.15
 */
import android.content.Context;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.text.Spannable;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;

public class Main{
    @SuppressWarnings("SameParameterValue")
    public static Spannable getCustomFontText(Context context,
            CharSequence text) {
        Spannable spannable = Spannable.Factory.getInstance().newSpannable(
                text);
        Typeface tf = Typeface.createFromAsset(context.getAssets(),
                "selection_icons.ttf");
        spannable.setSpan(new CustomTypefaceSpan("", tf), 0,
                spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannable;
    }
}

Related Tutorials