Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In android How to applying font for whole application?

Tags:

android

I want to apply some font say Times New Roman to only my application. Not to the whole system and not to specific view. As far I know

to apply font to specific view we store font file in asset folder and get into the application as follow.

1]  Typeface  mFace = Typeface.createFromAsset(getContext().getAssets(),
                                     "fonts/samplefont.ttf");
    textView.setTypeface(mFace);


2] To apply font to whole application I can replace the DroidSans.ttf file with my font file.

I can use first way to apply font to my application but It won't be a good solution because I need to modify everywhere and I don't want to do that if there is any better way is available.

like image 629
Vivek Avatar asked Mar 31 '11 12:03

Vivek


People also ask

How can I change font for all apps in Android?

In the Action Launcher Settings menu, tap the “Appearance” option. Scroll down within the “Appearance” menu and then tap “Font.” Choose one of the custom Action Launcher fonts available within the “Font” menu. Tap on one of the options to confirm your choice and then select the back button to return to your app drawer.


1 Answers

I made a custom textview widget and in the constructors made a call to this code:

public static void SetCustomFont (TextView t, String fontName, Context c) {
        Typeface tf = Typeface.createFromAsset(c.getAssets(),
                fontName);
        t.setTypeface(tf);
}

I'm using the same font over the whole application so I put the fontName in the constuctor and then did a global Find/Replace for TextView

like image 168
chedabob Avatar answered Nov 15 '22 21:11

chedabob