Helper object for injecting typeface into various text views of android.

Overview

TypefaceHelper

Gitter Android Arsenal License Circle CI

Helper object for injecting typeface into various text views of android.

Overview

We can use various custom typefaces asset for any text views(like TextView, Button, RadioButton, EditText, etc.), but there's no way to set the typeface as a styled theme to apply the typeface for overall screens in the app.

This library helps to do it in easy way :)

And there's also a serious bug that creating typeface from asset resource will cause memory leak (See this link for more details), this library will take care about this problem as well.

How to use

First, put your typeface into asset directory.

In your application class, take care about the helper object lifecycle.

public class MyApp extends Application {
  @Override
  public void onCreate() {
    super.onCreate();

    TypefaceHelper.initialize(this);
  }

  @Override
  public void onTerminate() {
    TypefaceHelper.destroy();
    super.onTerminate();
  }
}

And in your activity, if you would like to set your typeface to a text view,

public class MyActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView hello = (TextView) findViewById(R.id.hello_world);
    TypefaceHelper.getInstance().setTypeface(hello, "font/font_file.ttf");
  }
}

You can also set your typeface for all text views that belong to a specific view group just like this.

public class MyActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    LinearLayout container = (LinearLayout) findViewById(R.id.text_container);
    TypefaceHelper.getInstance().setTypeface(container, "font/font_file.ttf");
  }
}

If you want to apply the typeface for all text views under the activity layout,

public class MyActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(TypefaceHelper.getInstance().setTypeface(this, R.layout.activity_main, "font/font_file.ttf"));
  }
}

Nice and easy!

You can apply the typeface to your whole window like this.

public class MyActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_activity_main);
    TypefaceHelper.getInstance().setTypeface(this, "font/font_file.ttf");
  }
}

And... you can also pass the font name as a string resource id:

public class MyActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_activity_main);
    TypefaceHelper.getInstance().setTypeface(this, R.string.font_primary);
  }
}

Download

Gradle:

compile 'com.drivemode:TypefaceHelper:1.2.0@aar'

License

Copyright (C) 2014 Drivemode, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

And the sample app uses the following font under OFL.

You might also like...
A demo for Android font typeface support in React Native!
A demo for Android font typeface support in React Native!

A Step-by-step Guide to a Consistent Multi-Platform Font Typeface Experience in React Native Goal Be able to use font typeface modifiers such as fontW

A library that gives full control over text related technologies such as bidirectional algorithm, open type shaping, text typesetting and text rendering
A library that gives full control over text related technologies such as bidirectional algorithm, open type shaping, text typesetting and text rendering

Tehreer-Android Tehreer is a library which gives full control over following text related technologies. Bidirectional Algorithm OpenType Shaping Engin

Speech-Text Converter is a simple task that enable the user to convert the speech to text or convert text to speech (by Mic)
Speech-Text Converter is a simple task that enable the user to convert the speech to text or convert text to speech (by Mic)

Speech-Text Converter About Speech-Text Converter is a simple task that enable the user to convert the speech to text or convert text to speech (by Mi

A custom recycler view with shimmer views to indicate that views are loading.
A custom recycler view with shimmer views to indicate that views are loading.

ShimmerRecyclerView Intro A custom recycler view with shimmer views to indicate that views are loading. The recycler view has a built-in adapter to co

This library provides advance views for lists and stacks. Some of the views are build on top of RecyclerView and others are written in their own. Annotations are compiled by annotation processor to generate bind classes. DOCS -->
This library provides advance views for lists and stacks. Some of the views are build on top of RecyclerView and others are written in their own. Annotations are compiled by annotation processor to generate bind classes. DOCS --

PlaceHolderView An advance view for lists and stacks Some Implementations Documentation You can find the PlaceHolderView documentation here which has

SquircleView is a library which provides you with Squircle views to use for buttons, views, etc.
SquircleView is a library which provides you with Squircle views to use for buttons, views, etc.

SquircleView SquircleView is a library which provides you with Squircle views to use for buttons, views, etc. Screenshots Different kinds of buttons,

SquircleView is a library which provides you with Squircle views to use for buttons, views, etc.
SquircleView is a library which provides you with Squircle views to use for buttons, views, etc.

SquircleView is a library which provides you with Squircle views to use for buttons, views, etc.

Multi Lingual Chat app - A modern chat application that allows users to translate text messages into their preferred language
Multi Lingual Chat app - A modern chat application that allows users to translate text messages into their preferred language

Multi Lingual Chat app - A modern chat application that allows users to translate text messages into their preferred language

A editable text with a constant text/placeholder for Android.
A editable text with a constant text/placeholder for Android.

ParkedTextView A EditText with a constant text in the end. How to use com.goka.parkedtextview.ParkedTextView xmlns:app="http://schemas.android.co

A editable text with a constant text/placeholder for Android.
A editable text with a constant text/placeholder for Android.

ParkedTextView A EditText with a constant text in the end. How to use com.goka.parkedtextview.ParkedTextView xmlns:app="http://schemas.android.co

RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo
RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

Jetpack Compose Text composable to show html text from resources
Jetpack Compose Text composable to show html text from resources

HtmlText Current Compose Version: 1.0.3 Compose HtmlText Text composable to show html text from resources Add to your project Add actual HtmlText libr

Pdf Reader: Read text in PDF with Text to Speech
Pdf Reader: Read text in PDF with Text to Speech

PDF Reader PDF Reader Read text in PDF with Text to Speech APK Link Here | App D

Expandable text, similar to Text() in Jetpack Compose
Expandable text, similar to Text() in Jetpack Compose

A small library to display expandable texts in Jetpack Compose.

Object-relational mapping for Android

RushOrm Object-relational mapping for Android RushOrm replaces the need for SQL by mapping java classes to SQL tables. What is the aim? The aim is to

An Android project containing image recognition and object detection models.
An Android project containing image recognition and object detection models.

An Android project containing image recognition and object detection models. Users can input images into the deep learning model by taking photos, opening photo albums, and real-time previews on the Android side. After the calculation on the Android side is completed, the model will output the prediction result and show it to the user.

TensorFlow Lite Object Detection Android Demo
TensorFlow Lite Object Detection Android Demo

GSoC Project 2021 - TensorFlow Description This repository contains the project where I contributed to the TensorFlow Team during GSoC in the year 202

Kotlin Android object for global applicationContext

ContextProvider Kotlin Android object for global applicationContext Usage In your Aplication class class YourApp : Application() { override fun o

Based on Android + NodeMCU platform to achieve object detection and tracking, AI capabilities come from Google MLKit.
Based on Android + NodeMCU platform to achieve object detection and tracking, AI capabilities come from Google MLKit.

Based on Android + NodeMCU platform to achieve object detection and tracking, AI capabilities come from Google MLKit.

Comments
  • Use font support in Android O

    Use font support in Android O

    As Google added an official support for font and font-family, we don't need to put font files in assets directory any more and move them into font resource.

    https://developer.android.com/preview/features/fonts-in-xml.html

    opened by KeithYokoma 0
  • Fetching a Typeface from the TypefaceCache

    Fetching a Typeface from the TypefaceCache

    This library is great. However there are scenarios where you can set a widget's font only via its public methods.

    ex. public void setValueTypeface(Typeface tf)

    It would be great to have a method in TypefaceHelper that just returns the Typeface for a String resource.

    opened by cioraneanu 3
  • Issue with fragment and view other than textview

    Issue with fragment and view other than textview

    I am using the library in one of my project. For complete activity is works fine, but if the activity has an fragment it doesn't work then. Moreover inside the fragment it doens't work using one of the exposed methods. Also if i apply it to button or any view other then textview then also it doesn't work. Is it meant to work on these or just the acitivities. For a button , i use TypefaceHelper.getInstance().setTypeface(addPhotoBtn, "JosefinSans-Regular.ttf");

    opened by ankush19902 0
Owner
Drivemode, Inc.
No-look freedom for driving.
Drivemode, Inc.
A library that gives full control over text related technologies such as bidirectional algorithm, open type shaping, text typesetting and text rendering

Tehreer-Android Tehreer is a library which gives full control over following text related technologies. Bidirectional Algorithm OpenType Shaping Engin

Tehreer 61 Dec 15, 2022
Custom font library for android | Library to change/add font of Entire Android Application at once without wasting your time - TextViews, EditText, Buttons, Views etc.,

AppFontChanger In a Single shot change font of Entire Android Application - TextViews, EditText, Buttons, Views etc., Kindly use the following links t

Prabhakar Thota 48 Aug 10, 2022
Custom fonts in Android the easy way...

This version of Calligraphy has reached its end-of-life and is no longer maintained. Please migrate to Calligraphy 3! Calligraphy Custom fonts in Andr

Christopher Jenkins 8.6k Jan 3, 2023
A lightweight Android library for use iconic fonts.

Print A lightweight Android library for use iconic fonts. Download Gradle: compile 'com.github.johnkil.print:print:1.3.1' Maven: <dependency> <gro

Evgeny Shishkin 202 Dec 27, 2022
A lightweight Android library for use iconic fonts.

Print A lightweight Android library for use iconic fonts. Download Gradle: compile 'com.github.johnkil.print:print:1.3.1' Maven: <dependency> <gro

Evgeny Shishkin 202 Dec 27, 2022
An android library to display FontAwesome Icons in any View or a MenuItem

DroidAwesome A library to display FontAwesome Icons in any View or a MenuItem Views Supported: TextView AutoComplete TextView EditText Switch CheckBox

Livin 38 Aug 25, 2022
Android Library to use custom fonts with ease.

FontometricsLibrary A Simple Android Library to use Custom Fonts with Ease. Use Customs Fonts in your Android project without adding any .ttf/.otf in

Ishmeet Singh 188 Nov 15, 2022
Fontize is an Android library that enables multi-font selection functionality to diversify your app.

Fontize Android Library Built with ❤︎ by Gourav Khunger Fontize is an Android library, written in kotlin, that enables your android app have multiple

Gourav Khunger 8 Nov 28, 2022
Typeface helper for Android

Android Typeface Helper Android lacks proper support for custom typefaces. Most obvious method of defining typeface for UI elements via XML attributes

Norbsoft Sp. z o.o. 756 Aug 8, 2022
Android layout decorators : Injecting custom attributes in layout files, Using decorators to get rid of unnecessary class explosion with custom views

Decor Decor is a library that applies decorators to Android layout with additional attributes without the need to extend and create a custom View for

Mouna Cheikhna 304 Nov 25, 2022