Skip to content

Instantly share code, notes, and snippets.

@raviyadav4875
Created November 4, 2016 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raviyadav4875/2982cad770043d928f353d9fbd2db7dc to your computer and use it in GitHub Desktop.
Save raviyadav4875/2982cad770043d928f353d9fbd2db7dc to your computer and use it in GitHub Desktop.
public class TextViewCustom extends TextView {
private static final String TAG = TextViewCustom.class.getSimpleName();
public TextViewCustom(Context context) {
super(context);
}
public TextViewCustom(Context context, AttributeSet attrs) {
super(context, attrs);
parseAttributes(context, attrs); //I'll explain this method later
}
public TextViewCustom(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
parseAttributes(context, attrs);
}
private void parseAttributes(Context context, AttributeSet attrs) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomFont);
String customFont = typedArray.getString(R.styleable.CustomFont_font);
if (customFont != null && customFont.length() > 0) {
setTypeface(TypeFaceProvider.getTypeFace(context, customFont));
}
typedArray.recycle();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment