-
Notifications
You must be signed in to change notification settings - Fork 3
/
CustomFontButton.java
53 lines (43 loc) · 1.55 KB
/
CustomFontButton.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.android.kickstart.customview;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.provider.SyncStateContract;
import android.support.v7.widget.AppCompatButton;
import android.util.AttributeSet;
import com.android.kickstart.R;
import com.android.kickstart.utils.Constants;
/**
* CustomFontButton class to support custom fonts in Button
*/
public class CustomFontButton extends AppCompatButton {
private Context context;
public CustomFontButton(Context context) {
super(context);
}
public CustomFontButton(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
init(attrs);
}
public CustomFontButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
init(attrs);
}
private void init(AttributeSet attrs) {
if (attrs != null) {
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomFontTextView);
final String fontName = a.getString(R.styleable.CustomFontTextView_fontText);
try {
if (fontName != null) {
Typeface myTypeface = Typeface.createFromAsset(context.getAssets(), Constants.ASSETS_FOLDER_FONTS + fontName);
setTypeface(myTypeface);
}
} catch (Exception e) {
e.printStackTrace();
}
a.recycle();
}
}
}