How to get default Typeface of Android device?

Jack K Fouani picture Jack K Fouani · Aug 18, 2013 · Viewed 19.4k times · Source

I have an Api class in my application. Inside the Api class there is a custom font that has been setup as static. For example:

public static Typeface fontShort;

public Api(Context c, Display d) {
    // I want to change this if user wants to keep using system font style or my custom style
    if (shouldKeepCurrent == true) {
        // Use system default font
        fontTitle =  // ???
    } else {
        // Use my costume font
        fontTitle = Typeface.createFromAsset(context.getAssets(), "fonts/custom.ttf");
    }       
}

I want to get default and current Typeface of device if user doesn't want to use my custom font!

In Activity class:

TextView myView = (TextView) findViewById(R.id.myView);
// Change to custom font style or keep current font style
myView.setTypeface(Api.fontTitle);

Any ideas?

Answer

Vikram picture Vikram · Aug 18, 2013

You can get the default Typeface using:

if (keep_curren) {
    font_title = Typeface.DEFAULT;
}

You can also get the default Typeface based on specified style: Typeface.defaultFromStyle(int style).

More on this: Here.