Jack K Fouani Jack K Fouani - 4 months ago 31
Android Question

How to get default Typeface of Android device?

I have an API class inside my application; inside API class there is a custom font that has been setup as static, for example

public static Typeface font_short;

@SuppressWarnings("deprecation")
public Api(Context c , Display d)
{
this.context = c ;

//I want to change this if user wants to keep using System font style or my custom style
if ( keep_curren == true )
{
font_title = //What to add here to get Default fonts Typeface
}else
//use my costume font
{
font_title = Typeface.createFromAsset(context.getAssets(),"fonts/custome.ttf");
}

display = d;

w = display.getWidth(); // deprecated
h = display.getHeight(); // deprecated
}


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

in Activity Class

TextView blaaa = (TextView) findViewById(R.id.blaaa);
//change to custome font style or keep current font style
blaaa.setTypeface(Api.font_title);


Any ideas?

Answer

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.

Comments