I'm trying to add a custom font to my android application. I've added the font under 'assets' folder. I've come across code that allows you to add it programmatically to a specific view. I want to add the new font to my entire application and call it through my style.xml file
Asked
Active
Viewed 168 times
1 Answers
0
First add the font style file to the assets folder than create class file for accessing that font file.
FontStyle.java
public class FontStyle {
public static Typeface OswaldRegular(Context context) {
Typeface tf = null;
try {
tf = Typeface.createFromAsset(context.getAssets(), "Oswald-Regular.ttf");
} catch (Exception e) {
e.printStackTrace();
}
return tf;
}
}
Just replace your font file name into the above code and for that font style you can code into your MainActivity.java for
txt.setTypeface(FontStyle.OswaldRegular(CustomCameraActivity.this));
If anything you need to know, feel free to contact me.

Parth Bhayani
- 1,894
- 3
- 17
- 35