0

In my application i have not set typeface property for textviews in my app that is used to change font of textview.If someone runs the app on phone ,the default fonts used are the fonts set for the phone.I want my app to have only one font for all textviews in my app even if it is running on phone having different default font.My default fonts should be same on any phone.I dont want to use custom Textview.Is there a way to do this?

Mario
  • 145
  • 2
  • 16

2 Answers2

3

I hope it's not to late.

Use this library: Calligraphy

What you need to do is

1) Add this in your onCreate() method and select your font in the assets/fonts folder of your project.

CalligraphyConfig.initDefault("fonts/Roboto-Regular.ttf", R.attr.fontPath);

2) Wrap the activity context.

@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(new CalligraphyContextWrapper(newBase));
}

Do this for every activity! And thats it. :)

FullPatrickJoin
  • 184
  • 1
  • 7
0

For all the textviews you are declaring in your project you need to get the id in java code using findViewById and u need to set the typeface for each and every textview like following

font = Typeface.create("serif", Typeface.NORMAL);
myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setTypeface(font,Typeface.BOLD);

u need to set the font for all the textviews in your project in above way

Software Sainath
  • 1,040
  • 2
  • 14
  • 39
  • I want to change only at one place and it should reflect in whole application.In your method ill have to change every where in app – Mario Jan 20 '14 at 09:43
  • yep extend the Application class and declare font variable as static variable now set the font to all textviews whenever u want to change the font just change static font variable in Your Application class that reflects for all the texviews you have set – Software Sainath Jan 20 '14 at 09:45
  • currently i have many text view for which i didnt set typeface so i want to default typeface as one font so that it doesnt take phones default fonts.In above case ill have to go to each tect view and set typeface. – Mario Jan 20 '14 at 09:51
  • Then u need to have a custom textview and you need to replace the custom textview in all layouts – Software Sainath Jan 20 '14 at 10:12