Reputation: 10415
I did used uk.co.chrisjenx:calligraphy
dependency to use fonts from asset folder, however default font is not applied to my application. I followed the guideline used in other stackoverflow question but they did not work and all solutions used same syntax I used below.
Here is my application and path to font is correct since it works using XML fontpath
property;
public class App extends MultiDexApplication {
private static volatile Context instance;
public static Context get() {
return instance;
}
private static App enableMultiDex;
public static Context context;
public App(){
enableMultiDex=this;
}
public static App getEnableMultiDexApp() {
return enableMultiDex;
}
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
instance = getApplicationContext();
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/mobilefont.ttf")
.setFontAttrId(R.attr.fontPath)
.build());
}
}
Upvotes: 0
Views: 1021
Reputation: 1927
1. If you update your project with **API 33** or **Android 13** add below line for calligrapgy library.
ViewPump.init(ViewPump.builder()
.addInterceptor(new CalligraphyInterceptor(
new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/century_gothic.ttf")
.setFontAttrId(io.github.inflationx.calligraphy3.R.attr.fontPath)
.build())).build());
Upvotes: 2
Reputation: 1516
Wrap the Activity Context:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
Upvotes: 4