Giter VIP home page Giter VIP logo

android-font-library's Introduction

Android-Font-Library

This is a library that makes it easy for you to add custom fonts to your Android application. For a detailed description of why we made this library and how it works, please read this blogpost. For those that want a quickstart, read on below.

Gradle dependency

If you are using the Android Support Library, use this dependency to use font aware TextView's that extend from their AppCompat versions of the support library. The support library is not a transitive dependency, so you have to add it by yourself.

compile 'com.innovattic:fontlib-support:5.0.0'

Otherwise, use the following variant to use the font aware TextView's that extend from the native counterparts:

compile 'com.innovattic:fontlib-native:5.0.0'

Usage

To use the library, add it to your project as a gradle dependency, specify your font xml file, call TypefaceManager.init() (typically in your Application class' onCreate) and use any of the font aware TextViews.

A font xml file is placed in app/res/xml and can look like this:

<?xml version="1.0" encoding="utf-8"?>
<familyset>
	<family>
		<nameset>
			<name>aspergit</name>
			<name>any-alias</name>
		</nameset>
		<fileset>
			<file>aspergit/Aspergit.ttf</file>
			<file>aspergit/Aspergit Bold.ttf</file>
			<file>aspergit/Aspergit Italic.ttf</file>
			<file>aspergit/Aspergit Bold Italic.ttf</file>
		</fileset>
	</family>
</familyset>

In your layout xml files, use any of the font aware TextViews and set its flFont attribute to your font's name, like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:app="http://schemas.android.com/apk/res-auto"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:gravity="center_vertical"
	android:orientation="vertical">

	<com.innovattic.font.FontTextView
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="I am a text view with the font aspergit"
		app:flFont="aspergit" />

	<com.innovattic.font.FontTextView
		style="@style/AspergitStyle"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="I am a bold-italic text view with the font aspergit"
		android:textStyle="bold|italic" />

	<com.innovattic.font.FontTextView
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:textAppearance="@style/AspergitTextAppearance"
		android:text="I am a bold text view with the font aspergit" />
		
</LinearLayout>

Where the styles used in the last two FontTextView's are defined like this:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android" >

	<style name="AspergitStyle">
		<item name="flFont">aspergit</item>
	</style>

	<style name="AspergitTextAppearance">
		<item name="flFont">aspergit</item>
		<item name="android:textStyle">bold</item>
	</style>

</resources>

android-font-library's People

Contributors

jfresen avatar

Watchers

 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.