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?
Asked
Active
Viewed 2,472 times
2 Answers
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
-
I am using custom default font in my application which is working fine however I want to change font of one activity. How can I do? here is my question. http://stackoverflow.com/questions/31176166/different-font-for-some-activities-using-calligraphy-library – Ahmad Nawaz Jul 02 '15 at 05:25
-
-
What is the default path for the calligraphy exactly? Is it assets/fonts? – shadox Mar 22 '16 at 17:19
-
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