Skip to content

Instantly share code, notes, and snippets.

@guptasanchit90
Created November 20, 2015 16:38
Show Gist options
  • Save guptasanchit90/dd7b7720cdb6a84bae18 to your computer and use it in GitHub Desktop.
Save guptasanchit90/dd7b7720cdb6a84bae18 to your computer and use it in GitHub Desktop.
package <Package Name>;
import android.content.Context;
import android.graphics.Typeface;
import android.text.TextUtils;
public class FontUtils {
/**
* Loads the desired font.
*
* @param context This should be application context.
* @param fontName
* @return
*/
public static synchronized Typeface loadTypeFace(final Context context,
final String fontName) {
if (TextUtils.isEmpty(fontName)) {
throw new IllegalArgumentException("Font name can not be NULL!");
}
if (context == null) {
throw new IllegalArgumentException("Context name can not be NULL!");
}
Typeface typeFace = Typeface.createFromAsset(context.getAssets(), "fonts/" + fontName);
return typeFace;
}
public static Typeface getTypeface(Context context) {
return getTypeface(context, context.getString(R.string.font_file_name));
}
public static Typeface getTypeface(Context context, String fileName) {
return FontUtils.loadTypeFace(context, fileName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment