-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomTextView.java
30 lines (27 loc) · 1.1 KB
/
CustomTextView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class CustomTextView extends AppCompatTextView {
public CustomTextView(Context context) {
super(context);
init(context, (AttributeSet) null, 0);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr);
}
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
if (attrs != null) {
try {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomTextView);
String fontName = typedArray.getString(R.styleable.CustomTextView_typefamily);
if (fontName != null) {
Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/"+fontName);
setTypeface(typeface);
}
typedArray.recycle();
} catch (Exception unused) { }
}
}
}