Android Font Loading Textview

Helper for using custom fonts in styles

License

License

Categories

Categories

Net
GroupId

GroupId

net.kianoni
ArtifactId

ArtifactId

fontloader
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

aar
Description

Description

Android Font Loading Textview
Helper for using custom fonts in styles
Project URL

Project URL

https://github.com/Kianoni/android-fontloading-textview
Source Code Management

Source Code Management

https://github.com/Kianoni/android-fontloading-textview

Download fontloader

How to add to project

<!-- https://jarcasting.com/artifacts/net.kianoni/fontloader/ -->
<dependency>
    <groupId>net.kianoni</groupId>
    <artifactId>fontloader</artifactId>
    <version>0.3.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/net.kianoni/fontloader/
implementation 'net.kianoni:fontloader:0.3.0'
// https://jarcasting.com/artifacts/net.kianoni/fontloader/
implementation ("net.kianoni:fontloader:0.3.0")
'net.kianoni:fontloader:aar:0.3.0'
<dependency org="net.kianoni" name="fontloader" rev="0.3.0">
  <artifact name="fontloader" type="aar" />
</dependency>
@Grapes(
@Grab(group='net.kianoni', module='fontloader', version='0.3.0')
)
libraryDependencies += "net.kianoni" % "fontloader" % "0.3.0"
[net.kianoni/fontloader "0.3.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

android-fontloading-textview

Load custom fonts easily just via layout parameters or styles. Uses static Typeface objects, load once - memory efficient. No more textView.setTypeface() calls!

Android Arsenal

Add gradle dependency

compile 'net.kianoni:fontloader:0.3.0'

Usage in layouts

Please use styles.xml instead!

Add font namespace to xml root element, eg.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:font="http://schemas.android.com/apk/res-auto"

Define explicit font file to use:

<net.kianoni.fontloader.TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    font:fontFile="fonts/OpenSans-Regular.ttf"
    android:textSize="18sp"
    />

Or a pattern, family and variant:

<net.kianoni.fontloader.TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    font:fontFilePattern="fonts/{fontFamily}-{fontVariant}.ttf"
    font:fontFamily="OpenSans"
    font:fontVariant="Light"
    android:textSize="18sp"
    />

usage in styles

Example:

<resources xmlns:font="http://schemas.android.com/res/net.kianoni.fontloader">

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name="OpenSans">
        <item name="fontFilePattern">fonts/{fontFamily}-{fontVariant}.ttf</item>
        <item name="fontFamily">OpenSans</item>
        <item name="fontVariant">Regular</item>
        <item name="android:textSize">18sp</item>
    </style>

    <style name="OpenSans.Bold" parent="OpenSans">
        <item name="fontVariant">Bold</item>
    </style>

</resources>

and usage in layouts:

<net.kianoni.fontloader.TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    style="@style/OpenSans"
    />

<net.kianoni.fontloader.TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    style="@style/OpenSans.Bold"
    />

Versions

Version
0.3.0