Created
November 10, 2015 22:26
-
-
Save codeasashu/bb195683218405879d30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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