Giter VIP home page Giter VIP logo

calligraphy's Introduction

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 Central (.jar)

OR

Include the dependency:

dependencies {
    compile 'uk.co.chrisjenx:calligraphy:0.7.+'
}

IMPORTANT: The Maven artifact group id is now uk.co.chrisjenx NOT uk.co.chrisjenx.calligraphy (this changed in 0.7+)

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>

Custom font defined in Theme

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:textViewStyle">@style/AppTheme.Widget.TextView</item>
</style>

<style name="AppTheme.Widget"/>

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

Custom attribute

Defined your custom attribute name in your attr.xml (We don't ship calligraphy with one, this is so it can stay a jar).

<attr name="fontPath"/>

Then define in one of the places listed above, e.g:

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

#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)

As of 0.7+ you are able to define your own custom attributeId.

#Colaborators

calligraphy's People

Contributors

chrisjenx avatar manuelpeinado avatar nsk-mironov avatar shaunidiot avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.