1
1
<h1 > Sigmapoint Custom Button </h1 >
2
2
3
- <p > This button can help you to faster create button with background drawable, text color state, image inside button,
4
- you only must specify colors, position, drawables, etc in xml button tags.</p >
5
3
<p > If you want start use this button, you must clone or download this repository. Next in Android Studio File -> New -> Import module.
6
4
Then select library folder from project. And start use. </p >
7
5
<p > >=API 8 </p >
8
6
7
+ <h2 > Features </h2 >
8
+
9
+ * Use only custom tags in button declaration and reach state colors of text, background, frame and drawable.
10
+ * Add only one image and change it color dynamically
11
+ * Text color for normal, pressed and disabled state
12
+ * Background color for normal, pressed and disabled state
13
+ * Frame color for normal, pressed and disabled state
14
+ * Drawable color for normal, pressed and disabled state
15
+ * Specify image position and text will be centered with relation to whole button
16
+
17
+ See below to example:
18
+
19
+ image
20
+
21
+ For creating facebook button you must only do this:
22
+ ``` xml
23
+ <pl .sigmapoint.customview.CustomButton
24
+ android : layout_width =" match_parent"
25
+ android : layout_height =" 0dp"
26
+ android : layout_weight =" 5"
27
+ android : text =" Log in with facebook"
28
+ app : cb_image =" @drawable/ic_facebook"
29
+ app : cb_image_color_disabled =" #c0c0c0"
30
+ app : cb_image_color_normal =" #FFFFFF"
31
+ app : cb_image_color_pressed =" #c4cde0"
32
+ app : cb_image_padding =" 5dp"
33
+ app : cb_image_position =" left"
34
+ app : cb_primary_color =" #3B5998"
35
+ app : cb_secondary_color =" #17233c"
36
+ app : cb_shape_radius =" 5dp"
37
+ app : cb_text_color =" #FFFFFF" />
38
+ ```
39
+
9
40
<h2 > Reference </h2 >
10
41
<p > Default image position is left and centered text in button. When image is bigger than half of width, weight automatically is setting to 1. <br >
11
42
Only when image is in horizontal position text can be center. </p >
@@ -19,52 +50,52 @@ This is the base tag of CustomButton:<br>
19
50
android : layout_height =" match_parent"
20
51
android : text =" text" />
21
52
```
22
- <p > You can specify the following things:
23
- cb_primary_color - \/
24
- cb_secondary_color - you can specify only two colors for all button. But it will be override by background, text, frame color. {format - color} <br >
25
- cb_background - background color of normal button {format - color} <br >
26
- cb_background_pressed - background color of pressed button {format - color} <br >
27
- cb_background_disabled - background color of disabled button {format - color} <br >
28
- cb_background_state_list - {format - ColorStateList} <br >
53
+ <p > You can specify the following things: < br >
54
+ ` cb_primary_color ` - you can specify only two colors for all button. But it will be override by background, text, frame color. {format - color} < br >
55
+ ` cb_secondary_color ` - you can specify only two colors for all button. But it will be override by background, text, frame color. {format - color} <br >
56
+ ` cb_background ` - background color of normal button {format - color} <br >
57
+ ` cb_background_pressed ` - background color of pressed button {format - color} <br >
58
+ ` cb_background_disabled ` - background color of disabled button {format - color} <br >
59
+ ` cb_background_state_list ` - {format - ColorStateList} <br >
29
60
<br >
30
- cb_text_color_pressed - color of pressed text {format - color} <br >
31
- cb_text_color_disabled - color of disabled text {format - color} <br >
32
- cb_text_color or android: textColor - color of normal text {format - color} <br >
33
- cb_text_size - {format - dimension} <br >
34
- cb_text_padding - {format - dimension} <br >
35
- cb_text_padding_left - {format - dimension} <br >
36
- cb_text_padding_top - {format - dimension} <br >
37
- cb_text_padding_right - {format - dimension} <br >
38
- cb_text_padding_bottom - {format - dimension} <br >
39
- cb_text_weight - {format - integer} <br >
40
- cb_text_center or android: textAlignment - only works when image weight doesn't specify. Center text in button. {format - boolean or only "center" value} <br >
61
+ ` cb_text_color_pressed ` - color of pressed text {format - color} <br >
62
+ ` cb_text_color_disabled ` - color of disabled text {format - color} <br >
63
+ ` cb_text_color ` or ` android:textColor ` - color of normal text {format - color} <br >
64
+ ` cb_text_size ` - {format - dimension} <br >
65
+ ` cb_text_padding ` - {format - dimension} <br >
66
+ ` cb_text_padding_left ` - {format - dimension} <br >
67
+ ` cb_text_padding_top ` - {format - dimension} <br >
68
+ ` cb_text_padding_right ` - {format - dimension} <br >
69
+ ` cb_text_padding_bottom ` - {format - dimension} <br >
70
+ ` cb_text_weight ` - {format - integer} <br >
71
+ ` cb_text_center ` or ` android:textAlignment ` - only works when image weight doesn't specify. Center text in button. {format - boolean or only "center" value} <br >
41
72
<br >
42
- cb_shape_radius - corner radius {format - dimension}<br >
43
- cb_shape_type - shape type, you can choose: rect or oval <br >
44
- cb_frame_color - {format - color} <br >
45
- cb_frame_color_pressed - {format - color} <br >
46
- cb_frame_color_disabled - {format - color} <br >
47
- cb_frame_size - frame height {format - dimension} <br >
48
- cb_frame_state_list - {format - ColorStateList} <br >
73
+ ` cb_shape_radius ` - corner radius {format - dimension}<br >
74
+ ` cb_shape_type ` - shape type, you can choose: rect or oval <br >
75
+ ` cb_frame_color ` - {format - color} <br >
76
+ ` cb_frame_color_pressed ` - {format - color} <br >
77
+ ` cb_frame_color_disabled ` - {format - color} <br >
78
+ ` cb_frame_size ` - frame height {format - dimension} <br >
79
+ ` cb_frame_state_list ` - {format - ColorStateList} <br >
49
80
<br >
50
- cb_elevation_enabled - on >=API 21 devices enable elvation (default) {format - boolean} <br >
81
+ ` cb_elevation_enabled ` - on >=API 21 devices enable elvation (default) {format - boolean} <br >
51
82
<br >
52
- cb_image_position - image position in button, can choose left, top, right, bottom <br >
53
- cb_image - image source {format - drawable or color} <br >
54
- cb_image_normal - normal state image source (if you choose cb_image, it will be override) {format - drawable or color} <br >
55
- cb_image_disabled - disabled state image source (if you choose cb_image, it will be override) {format - drawable or color} <br >
56
- cb_image_pressed - pressed state image source (if you choose cb_image, it will be override) {format - drawable or color} <br >
57
- cb_image_color_normal - only for image {format - color} <br >
58
- cb_image_color_pressed - only for image {format - color} <br >
59
- cb_image_color_disable - only for image {format - color} <br >
60
- cb_image_color_list - only for image {format - colorStateList} <br >
61
- cb_image_padding - {format - dimension} <br >
62
- cb_image_padding_left - {format - dimension} <br >
63
- cb_image_padding_top - {format - dimension} <br >
64
- cb_image_padding_right - {format - dimension} <br >
65
- cb_image_padding_bottom - {format - dimension} <br >
66
- cb_image_scale_type - {center, center_inside, center_crop, fit_center, fit_start, fit_end, fit_xy} <br >
67
- cb_image_weight - {format - integer} </p >
83
+ ` cb_image_position ` - image position in button, can choose left, top, right, bottom <br >
84
+ ` cb_image ` - image source {format - drawable or color} <br >
85
+ ` cb_image_normal ` - normal state image source (if you choose cb_image, it will be override) {format - drawable or color} <br >
86
+ ` cb_image_disabled ` - disabled state image source (if you choose cb_image, it will be override) {format - drawable or color} <br >
87
+ ` cb_image_pressed ` - pressed state image source (if you choose cb_image, it will be override) {format - drawable or color} <br >
88
+ ` cb_image_color_normal ` - only for image {format - color} <br >
89
+ ` cb_image_color_pressed ` - only for image {format - color} <br >
90
+ ` cb_image_color_disable ` - only for image {format - color} <br >
91
+ ` cb_image_color_list ` - only for image {format - colorStateList} <br >
92
+ ` cb_image_padding ` - {format - dimension} <br >
93
+ ` cb_image_padding_left ` - {format - dimension} <br >
94
+ ` cb_image_padding_top ` - {format - dimension} <br >
95
+ ` cb_image_padding_right ` - {format - dimension} <br >
96
+ ` cb_image_padding_bottom ` - {format - dimension} <br >
97
+ ` cb_image_scale_type ` - {center, center_inside, center_crop, fit_center, fit_start, fit_end, fit_xy} <br >
98
+ ` cb_image_weight ` - {format - integer} </p >
68
99
<h3 > Java Code </h3 >
69
100
``` java
70
101
CustomButton(Context context, LayoutParams layoutParams, int primaryColor, int secondaryColor, Drawable icon)
@@ -97,6 +128,7 @@ setTextPadding(int[] padding) - int[4]{CustomButton.LEFT, CustomButton.TOP, Cust
97
128
setTextParams(int weight, int [] padding)
98
129
setImage(int position, Drawable drawableNormal, Drawable drawablePressed, Drawable drawableDisabled, ImageView . ScaleType scaleType, int weight, int [] padding)
99
130
setImage(int position, Drawable drawable, ImageView . ScaleType scaleType, int weight, int [] padding)
131
+ setImageColor(int color)
100
132
setImageColors(int nomal, int pressed, int disabled)
101
133
setImageNormalColor(int color)
102
134
setImagePressedColor(int color)
@@ -107,6 +139,9 @@ and evry XML tag have getter
107
139
<h3 > Static field </h3 >
108
140
LEFT, TOP, RIGHT, BOTTOM - for image position
109
141
142
+ <h3 > Tips </h3 >
143
+ If you add image to the button, set frame and want to center text without respect frame you should set text padding same as frame size.
144
+
110
145
<h2 > Dependencies </h2 >
111
146
In demo application <a href =" https://github.com/yukuku/ambilwarna " > Ambil Warna Library</a > was used.
112
147
0 commit comments