-
Notifications
You must be signed in to change notification settings - Fork 3
/
CustomFontEditText.java
53 lines (42 loc) · 1.52 KB
/
CustomFontEditText.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.support.v7.widget.AppCompatEditText;
import android.util.AttributeSet;
import com.android.kickstart.R;
import com.android.kickstart.utils.Constants;
/**
* CustomFontEditText class to support custom fonts in EditText
*/
public class CustomFontEditText extends AppCompatEditText {
private Context context;
public CustomFontEditText(Context context) {
super(context);
}
public CustomFontEditText(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
init(attrs);
}
public CustomFontEditText(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();
}
}
}