-2

I have one application in Which I want to change font of text in whole application.
Is there anyway to change font of application Programmatically or with xml in manifest.?

Kuffs
  • 35,581
  • 10
  • 79
  • 92
Ando Masahashi
  • 3,112
  • 2
  • 24
  • 41
  • 3
    see http://stackoverflow.com/questions/7858860/android-change-font-type-of-application and http://stackoverflow.com/questions/16404820/how-to-set-default-font-family-for-entire-android-app – Shayan Pourvatan Dec 17 '13 at 09:29
  • 2
    i believe this has been answered n number of time. please go through the forum. – Yogamurthy Dec 17 '13 at 09:35

4 Answers4

2

Try this

1.place your ttf file in assets folder and add these lines to your java file

Typeface font = Typeface.createFromAsset(activity.getAssets(),"fonts/androidnation.ttf");

tv.setTypeface(font);

2.To set it through xml

XML Typeface

Community
  • 1
  • 1
Vaibhav Agarwal
  • 4,499
  • 3
  • 19
  • 20
0

The easiest way to do it is creating your own TextView:

public class MyTextView extends TextView {

    public DMTextView(Context context, AttributeSet attrs) {
      super(context, attrs);
      // you need your TypefaceFile "myTypeface.ttf" in the assets folder of your project
      setTypeface(Typeface.createFromAsset(context.getAssets(),"myTypeface.ttf"));
    }

    // add the other constructors if you want
}

now, you can use it anywhere in your xml: <com.your.package.MyTextView ... > just like normal textviews

It might be improved by caching the Typeface, so you don't have to create it again with every Reference to your TextView.

gprathour
  • 14,813
  • 5
  • 66
  • 90
Lovis
  • 9,513
  • 5
  • 31
  • 47
  • 1
    really kind to downvote an answer and don't tell why. How am I supposed to know what I was doing wrong for two years (and was always working fine) if you don't tell me?! Thanks a lot, little minds. – Lovis Dec 17 '13 at 10:01
0

Place you fonts in fonts folder and then use the following code.

TextView tv = (TextView) findViewById(R.id.appname);
Typeface face = Typeface.createFromAsset(getAssets(),"fonts/epimodem.ttf");
tv.setTypeface(face);

This is the way to set font programmatically.

Yogamurthy
  • 988
  • 15
  • 22
0

Create fonts folder in asset and paste the fonts whatever you want to paste.

Create one class. Name it Typesafe.java

public enum TypeSafe {
   HELVETICANEUELTCOMBD,
   HELVETICANEUELTCOMBDCN,
   HELVETICANEUELTCOMCN,
}

After that create one method in your Activity or if you have the Utility class.

public void setTypeface(TextView textView, TypeSafe type, AssetManager assetManager){
    if (TypeSafe.HELVETICANEUELTCOMBD.equals(type)) {
        final Typeface typeface = Typeface.createFromAsset(assetManager, "fonts/HelveticaNeueLTCom-Bd.ttf");
        textView.setTypeface(typeface);
    } else if (TypeSafe.HELVETICANEUELTCOMBDCN.equals(type)) {
        final Typeface typeface1 = Typeface.createFromAsset(assetManager, "fonts/HelveticaNeueLTCom-BdCn.ttf");
        textView.setTypeface(typeface1);
    } 
}

Call these method in your activity.

setTypeface(yourtextView, TypeSafe.HELVETICANEUELTCOMLT, getAssets());
Sulabh Gajjar
  • 496
  • 4
  • 16