CustomFontButton.java
1.5 KB
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
54
55
56
57
58
package com.xdy.ui.fontview;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.Button;
/**
* A simple button with extra attributes to allow font customization.
*/
public class CustomFontButton extends Button {
/**
* Default View Constructor.
*
* @param context application context.
*/
public CustomFontButton(final Context context) {
super(context);
}
/**
* Default View Constructor. Sets custom font with no style.
*
* @param context application context.
* @param attrs View attributes.
*/
public CustomFontButton(final Context context, final AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
/**
* Default View Constructor. Sets custom font with style.
*
* @param context application context.
* @param attrs View attributes.
* @param defStyle View Style.
*/
public CustomFontButton(final Context context, final AttributeSet attrs,
final int defStyle) {
super(context, attrs, defStyle);
init(attrs);
}
/**
* Initialize custom font attribute.
*
* @param attrs attributes.
*/
private void init(final AttributeSet attrs) {
Typeface typeface;
if (!isInEditMode() && (typeface = CustomFontUtils.getTypeFace(this, attrs)) != null) {
super.setTypeface(typeface, typeface.getStyle());
}
}
}