Created
February 24, 2014 04:06
-
-
Save jackmahoney/9181787 to your computer and use it in GitHub Desktop.
Set custom font on an android custom textview. Untested code, be sure to test.
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 TextHelper{ | |
private static TypeFace typeface = null; | |
public static void setTypeface(Context context, TextView textview){ | |
if(this.typeface == null){ | |
this.typeface = Typeface.createFromAsset(context.getAssets(), "Helvetica_Neue.ttf"); | |
} | |
textview.setTypeface(face); | |
} | |
} | |
public class FontTextView extends TextView { | |
public FontTextView(Context context) { | |
super(context); | |
TextHelper.setTypeface(context, this); | |
} | |
} | |
so smth like this?
`
class TextHelper{
private static Typeface typeface = null;
public static void setTypeface(Context context, TextView textview){
if(typeface == null){
typeface = Typeface.createFromAsset(context.getAssets(), "Helvetica_Neue.ttf");
}
textview.setTypeface(typeface);
}
}
public class CustomTextView extends TextView {
public CustomTextView(Context context){
super(context);
TextHelper.setTypeface(context, this);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
TextHelper.setTypeface(context, this);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TextHelper.setTypeface(context, this);
}
protected void onDraw (Canvas canvas) {
super.onDraw(canvas);
}
}
`
Nice , Thanks
Great !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 9 : textview.setTypeface(typeface) is more exactly