Jayesh Rathod
Jayesh Rathod

Reputation: 620

chrisjenx/calligraphy not work properly in my app tried so many answered

I tried so many examples and answered from other questions on this library but not working for me. I don't know what was happened with this?

Application class :

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
            .setDefaultFontPath("fonts/choco-cookie.ttf")
            .setFontAttrId(R.attr.fontPath)
            .build());
    }
}

AndroidManifest.xml :

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:name=".Utils.MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".Design.DashboardActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Also attached to Activity :

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

And font available in 'assets/fonts/choco-cookie.ttf'.

Problem is not changing fonts of all over app!

Upvotes: 1

Views: 506

Answers (1)

em_
em_

Reputation: 2269

Make sure you register your custom Application in the Manifest

<application
  android:name=".MyApplication" <----------- HERE
  android:allowBackup="true"
  android:icon="@mipmap/ic_launcher"
  android:label="@string/app_name"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:supportsRtl="true"
  android:theme="@style/AppTheme">

Upvotes: 1

Related Questions