Created
August 31, 2016 06:20
-
-
Save arthtilva/82b835cb1a1abf4d6473271383c4da92 to your computer and use it in GitHub Desktop.
Custom Font TextView
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 CTextView extends TextView { | |
public static final String ANDROID_SCHEMA = "http://schemas.android.com/apk/res/android"; | |
public CTextView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
applyCustomFont(context, attrs); | |
} | |
public CTextView(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