Skip to content

Instantly share code, notes, and snippets.

@codeasashu
Created November 10, 2015 22:26
Show Gist options
  • Save codeasashu/bb195683218405879d30 to your computer and use it in GitHub Desktop.
Save codeasashu/bb195683218405879d30 to your computer and use it in GitHub Desktop.
package com.company.app.helper;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import java.io.File;
/**
* Created by Sid on 11/11/2015.
*/
public class FontLoader {
private Typeface typeFace;
private Context context;
private String font = "Helvetica-Regular.ttf";
public FontLoader(Context context) {
this.context = context;
this.setFont(font);
}
public Typeface getFont(){
return typeFace;
}
public void setFont(String font){
try {
typeFace = Typeface.createFromAsset( context.getAssets(), "fonts" + File.separator + font );
}
catch (RuntimeException e) {
// createFromAsset() will throw a RuntimeException in case of error.
Log.e("Typeface", "Unable to create font: " + font, e);
typeFace = Typeface.defaultFromStyle( Typeface.NORMAL );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment