Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different font for Some activities using Calligraphy Library

I am using Calligraphy Library for using custom font in my application. I set a custom font to my whole application by default font using CalligraphyConfig, in my Application class in the #onCreate() method and it is working fine. Problem comes when I need to change font of one activity (SettingsActivity).

I tried using custom font in style however It didn't change the font of activity.

Following is the code of Style

    <style name="EnglishActivitiesTheme" parent="AppTheme">
        <item name="android:textViewStyle">@style/AppTheme.Widget.TextView</item>
    </style>

    <style name="AppTheme.Widget.TextView" parent="android:Widget.Holo.Light.TextView">
        <item name="fontPath">fonts/Roboto-Regular.ttf</item>
    </style>

In Manifest

    <activity
        android:name=".SettingsActivity"
        android:theme="@style/EnglishActivitiesTheme"
        android:parentActivityName=".MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity" />
    </activity>

Am I doing something wrong with custom font though style method? or Is there better method of doing this?

like image 306
Ahmad Nawaz Avatar asked Jul 02 '15 05:07

Ahmad Nawaz


People also ask

What font is used for calligraphy?

Nickainley. A casual monoline script font with a touch of vintage is the perfect calligraphy font to be used for any informal uses where high legibility is required.

How many types of calligraphy fonts are there?

There are three main types of calligraphy: western, eastern, and Arabic. Each type reflects the language and handwriting of a different region of the world.

Which font is most like calligraphy?

Corneria Script is a formal, traditional calligraphy font created by Mans Greback. Corneria is a great choice for logos, titles and slogans.


1 Answers

Looks like it's because of AppCompat creating a different version of buttons/textviews at runtime.

In your Calligraphy startup in your Application, add the line:

.addCustomStyle(AppCompatTextView.class, android.R.attr.textViewStyle)

to end up with something like:

@Override
public void onCreate() {
    super.onCreate();
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                            .setDefaultFontPath("fonts/some-other-custom-font.ttf")
                            .addCustomStyle(AppCompatTextView.class, android.R.attr.textViewStyle)
                            .setFontAttrId(R.attr.fontPath)
                            .build()
            );
    //....
}

And that should take care of your textviews.

Edit:

This should now be fixed with https://github.com/chrisjenx/Calligraphy/pull/191, currently as a snapshot.

like image 139
pturner Avatar answered Sep 28 '22 19:09

pturner