Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Latest commit

 

History

History
51 lines (40 loc) · 1.29 KB

README.md

File metadata and controls

51 lines (40 loc) · 1.29 KB

fontcustomizer

Android module for easy using a custom fonts in the project

How to use:

  • Project -> New -> Module -> Import Gradle Project
  • add dependency to build.gradle
dependencies {

....

compile project(':fontcustomizer');
}
  • put your [font-file].ttf files into app/src/main/assets/fonts;
  • in onCreate() method (of Application or Activity or Fragment) call this for caching all names of the fonts located in the assets/fonts:
        FontCache.getInstance(getApplicationContext());

or call this for each .ttf for caching a custom names of the fonts:

        FontCache.getInstance(getApplicationContext()).addFont("any-name", "[font-file].ttf");
  • apply font:
textView.setTypeface(
    FontCache.getInstance(getApplicationContext()).get("any-name")
);

Example:

public class AppController extends Application{

    @Override
    public void onCreate() {
        super.onCreate();
        Context context = getApplicationContext();

        //Add custom font to HashMap
        FontCache.getInstance(context).addFont("regular", "SourceSansPro-Regular.ttf");
        FontCache.getInstance(context).addFont("semibold", "SourceSansPro-Semibold.ttf");
        FontCache.getInstance(context).addFont("light", "SourceSansPro-Light.ttf");
    }
    
}