Last active
August 31, 2016 07:03
-
-
Save arthtilva/0e42fa2258a9531e84abdc1edda0afb3 to your computer and use it in GitHub Desktop.
Custom Font EditText
This file contains hidden or 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 CEditText extends TextInputEditText { | |
public static final String ANDROID_SCHEMA = "http://schemas.android.com/apk/res/android"; | |
public CEditText(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
applyCustomFont(context, attrs); | |
} | |
public CEditText(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
applyCustomFont(context, attrs); | |
} | |
private void applyCustomFont(Context context, AttributeSet attrs) { | |
int textStyle = attrs.getAttributeIntValue(ANDROID_SCHEMA, "textStyle", Typeface.NORMAL); | |
Typeface customFont = selectTypeface(context, textStyle); | |
setTypeface(customFont); | |
} | |
private Typeface selectTypeface(Context context, int textStyle) { | |
switch (textStyle) { | |
case Typeface.BOLD: | |
return Typeface.createFromAsset(context.getAssets(), "DIN Next W01 Regular.ttf"); | |
case Typeface.NORMAL: | |
return Typeface.createFromAsset(context.getAssets(), "DIN Next W01 Light.ttf");// regular | |
default: | |
return Typeface.createFromAsset(context.getAssets(), "DIN Next W01 Light.ttf");// regular | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment