CustomType, An Android Library For The Typography Enthusiast

CustomType, An Android Library For The Typography Enthusiast

All across our tech stack at Haptik, we’ve benefitted enormously from the Open Source community. And every one of us, right from day 1, had a personal goal of wanting to give back in some form, big or small. Today, we have the privilege of announcing our first contribution: CustomType for Android.

 

CustomType for Android

 

Being a messaging app, typography plays an important part of our design. However, using custom typefaces within an Android app isn’t easy: there are limitations which prevent us from specifying the typeface in the layout XML file itself, and also performance issues to be handled while creating the Typeface objects in the Java code.

 

To handle these issues, we had written CustomType in the middle of last year. While in truth it’s a very, very small library (the aar is only 5kb), it’s impact is huge since it handles the two issues outlined earlier. And it does so with minimal programming. In fact, while implementing in Java, CustomType decreases the amount of code you need to write. All you need to do is

 

<span style="color: #a9b7c6;">view.setTypeface(CustomType.</span><span style="color: #a9b7c6;"><i>getTypeface</i></span><span style="color: #a9b7c6;">(</span><span style="color: #cc7832;">this,</span><span style="color: #6a8759;">"fonts/typeface.ttf"</span><span style="color: #a9b7c6;">))</span><span style="color: #cc7832;">;</span>

 

You can also use custom typefaces from the XML files, though this would require you to use a bundled custom TextView instead of the standard TextView.

 

<span style="color: #e8bf6a;">&lt;in.raveesh.customtype.TextView
</span> <span style="color: #bababa;">android:text=</span><span style="color: #a5c261;">"@string/lorem_ipsum_short"
</span> <span style="color: #bababa;">android:layout_width=</span><span style="color: #a5c261;">"wrap_content"
</span> <span style="color: #bababa;">android:layout_height=</span><span style="color: #a5c261;">"wrap_content"
</span> <span style="color: #bababa;">app:typeface=</span><span style="color: #a5c261;">"fonts/RobotoCondensed/Light.ttf"
</span> <span style="color: #bababa;">android:textSize=</span><span style="color: #a5c261;">"@dimen/typesize_headline"
</span> <span style="color: #bababa;">android:textColor=</span><span style="color: #a5c261;">"@color/text_primary_light"</span><span style="color: #e8bf6a;">/&gt;
</span>

 

We’ve also bundled a few useful resources, such as Lorem Ipsum of three different lengths, and the type sizes as per the Material Design spec and colors that the spec recommends for type.
 

To get started with CustomType, head over to the repository on Github.

Related Articles

View All