set View Text Font - Android Graphics

Android examples for Graphics:Font

Description

set View Text Font

Demo Code


//package com.java2s;

import android.graphics.Typeface;

import android.view.View;

import android.widget.TextView;

public class Main {

    public static void setTextFont(View view, String fontName) {
        if (null == view || !(view instanceof TextView)) {
            return;
        }//  www. j a  v  a 2 s . co  m

        Typeface typeface = Typeface.createFromAsset(view.getContext()
                .getResources().getAssets(), fontName);
        if (null == typeface) {
            return;
        }
        ((TextView) view).setTypeface(typeface);
    }
}

Related Tutorials