Created
January 30, 2014 08:51
-
-
Save oguya/8704814 to your computer and use it in GitHub Desktop.
set custom fonts in java
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 MyApplication extends Application { | |
private Typeface normalFont; | |
private Typeface boldFont; | |
//FontSetter fontSetter = (FontSetter) getApplication(); | |
//TextView myTextView = (TextView) findViewById(R.id.my_textview); | |
//application.setTypeface(myTextView); | |
// -- Fonts -- // | |
public void setTypeface(TextView textView) { | |
if(textView != null) { | |
if(textView.getTypeface() != null && textView.getTypeface().isBold()) { | |
textView.setTypeface(getBoldFont()); | |
} else { | |
textView.setTypeface(getNormalFont()); | |
} | |
} | |
} | |
private Typeface getNormalFont() { | |
if(normalFont == null) { | |
normalFont = Typeface.createFromAsset(getAssets(),"fonts/my_font.ttf"); | |
} | |
return this.normalFont; | |
} | |
private Typeface getBoldFont() { | |
if(boldFont == null) { | |
boldFont = Typeface.createFromAsset(getAssets(),"fonts/my_font_bold.ttf"); | |
} | |
return this.boldFont; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment