Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
Created January 26, 2017 06:33
Show Gist options
  • Save talhahasanzia/564ba68a4187a6b6d7151000a756557d to your computer and use it in GitHub Desktop.
Save talhahasanzia/564ba68a4187a6b6d7151000a756557d to your computer and use it in GitHub Desktop.
Custom font in a predefined textview
public class CustomFontTextView extends TextView
{
public CustomFontTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public CustomFontTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomFontTextView(Context context) {
super(context);
init();
}
private void init() {
if (!isInEditMode()) {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "Sans-Bold.ttf");
setTypeface(tf);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment