Skip to content

Instantly share code, notes, and snippets.

@layerlre
Created April 28, 2015 08:30
Show Gist options
  • Save layerlre/5c57c2a081cd939a280a to your computer and use it in GitHub Desktop.
Save layerlre/5c57c2a081cd939a280a to your computer and use it in GitHub Desktop.
public class TextViewTH extends TextView {
public TextViewTH(Context context) {
super(context);
//mContext = context;
setFont();
}
public TextViewTH(Context context, AttributeSet attrs) {
super(context, attrs);
//mContext = context;
setFont();
}
public TextViewTH(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
//mContext = context;
setFont();
}
private void setFont() {
int style = Typeface.NORMAL;
try {
style = getTypeface().getStyle();
} catch (Exception e) {
//e.printStackTrace();
}
Typeface face;
if (style == Typeface.NORMAL) {
//face = Typeface.createFromAsset(getContext().getAssets(), "fonts/ThaiSansNeue-Black.ttf");
face = Typeface.createFromAsset(getContext().getAssets(), "fonts/ThaiSansNeue-Light.ttf");
} else if (style == Typeface.BOLD) {
//face = Typeface.createFromAsset(getContext().getAssets(), "fonts/ThaiSansNeue-Bold.ttf");
face = Typeface.createFromAsset(getContext().getAssets(), "fonts/ThaiSansNeue-Black.ttf");
// } else if (style == Typeface.ITALIC){
// face = Typeface.createFromAsset(getContext().getAssets(), "fonts/ThaiSansNeue-Light.ttf");
} else {
face = Typeface.createFromAsset(getContext().getAssets(), "fonts/ThaiSansNeue-ExtraBlod.ttf");
}
this.setTypeface(face);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment