Created
November 20, 2015 16:38
-
-
Save guptasanchit90/dd7b7720cdb6a84bae18 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 <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