Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top