Created
February 6, 2015 13:00
-
-
Save alorma/e4f565142559071d0b00 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
public class FontUtils { | |
public static void wrap(TextView textView) { | |
if (textView != null) { | |
try { | |
String fontName = FontUtils.fontName(textView); | |
if (fontName != null) { | |
Typeface typeface = Typeface.createFromAsset(textView.getContext().getAssets(), "fonts/" + fontName); | |
textView.setTypeface(typeface); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
private static String fontName(TextView textView) { | |
if (textView.getTypeface() != null) { | |
int style = textView.getTypeface().getStyle(); | |
if (textView.getTypeface().isBold()) { | |
return "bold.otf"; | |
} else if (textView.getTypeface().isItalic()) { | |
return "italic.otf"; | |
} else if ((style & Typeface.BOLD_ITALIC) != 0) { | |
return "bold_italic.otf"; | |
} | |
} | |
return "regular.otf"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment