Skip to content
Custom fonts in Android the easy way...
Branch: master
Clone or download
Pull request Compare This branch is 274 commits behind chrisjenx:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
CalligraphySample
calligraphy
gradle/wrapper
.gitignore
CHANGELOG.md
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
screenshot.png
settings.gradle

README.md

Calligraphy

Custom fonts in Android the easy way.

Are you fed up of Custom views to set fonts? Or traversing the ViewTree to find TextViews? Yeah me too.

alt text

##Getting started

Download from Maven (.jar)

OR

Include the dependency: (Waiting to be synced with MavenCentral.)

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/groups/staging" }
}
dependencies {
    compile 'uk.co.chrisjenx.calligraphy:calligraphy:0.5.+'
}

Add your custom fonts to assets/ all font definition is relative to this path.

Define your default font using CalligraphyConfig.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CalligraphyConfig.initDefault("fonts/Roboto-Regular.ttf");
    //....
}

###Important

Wrap the Activity Context:

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

You're good to go!


Custom font per TextView

Of course:

<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="fonts/Roboto-Bold.ttf"/>

Custom font in styles

No problem:

<style name="TextViewCustomFont">
    <item name="android:fontFamily">fonts/RobotoCondensed-Regular.ttf</item>
</style>

#FAQ

Why piggyback off of fontFamily attribute?

Means the the library can compile down to a jar instead of an aar, as it is not dependant on any resources. (This may of course change in the future if we run into issues)

CustomText/Button View support

Coming soon!

You can’t perform that action at this time.