I want to apply Font type without using XML. By code, I want to change Font type and it should be able to apply for a whole application, when I click Arial else Times New Roman etc.
Asked
Active
Viewed 1,751 times
2 Answers
1
try this code to change the font of app
TypeFace typeFace = Typeface.createFromAsset(getAssets(), "font.ttf");
TextView view= (TextView) findViewById(R.id.view);
view.setTypeface(typeFace)

Naveen Kumar
- 3,738
- 4
- 29
- 50
-
What is that "font.ttf". It is a XML file right ? Without using XML, in my main code i have to apply Font type . For that i have to write a code. How could i do this ? – Achiever Oct 11 '12 at 04:43
-
it is the font lib that u can download from internet and it is .ttf type download it from internet and copy into your asset folder – Naveen Kumar Oct 11 '12 at 04:48
-
.ttf stand for True Type Font library – Naveen Kumar Oct 11 '12 at 04:51
0
I would reccomend having a list preference, in a preference screen. You can then set the fonts from that. i.e:
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
String font = sp.getString("font","-1")
if(font.equals("timesroman")) {
TypeFace typeFace = Typeface.createFromAsset(getAssets(), "timesnewroman.ttf");
}
else if(font.equals("arial")) {
TypeFace typeFace = Typeface.createFromAsset(getAssets(), "arial.ttf");
}
TextView view= (TextView) findViewById(R.id.view);
view.setTypeface(typeFace)

SquiresSquire
- 2,404
- 4
- 23
- 39