-
-
Save bblackbelt/c6698693556b71c4ff31 to your computer and use it in GitHub Desktop.
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<declare-styleable name="FontTextView"> | |
<attr name="fontName" format="string"/> | |
</declare-styleable> | |
</resources> |
This file contains 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 FontTextView extends TextView { | |
public FontTextView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FontTextView); | |
setFont(a.getString(R.styleable.FontTextView_fontName); | |
a.recycle(); | |
} | |
public FontTextView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FontTextView); | |
setFont(a.getString(R.styleable.FontTextView_fontName); | |
a.recycle(); | |
} | |
public FontTextView(Context context) { | |
super(context); | |
} | |
public void setFont(String fontName) { | |
if (!isInEditMode()) { | |
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), fontName); | |
setTypeface(tf); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment