Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get default Typeface of Android device?

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?

like image 346
Noob Avatar asked Aug 17 '13 22:08

Noob


People also ask

What is default typeface in Android?

SANS_SERIF. The NORMAL style of the default sans serif typeface.

What is the default phone font?

Roboto is the default font on Android and other Google services.


1 Answers

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.

like image 119
Vikram Avatar answered Sep 27 '22 05:09

Vikram