Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 805dd15

Browse files
committed
Added the ability to change success and error background with icons
1 parent c888104 commit 805dd15

7 files changed

Lines changed: 80 additions & 43 deletions

File tree

README.md

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,46 @@ For using custom attributes use `app` namespace
2828
xmlns:app="http://schemas.android.com/apk/res-auto"
2929
```
3030
```xml
31-
<com.droidbond.loadingbutton.LoadingButton
32-
android:layout_width="wrap_content"
33-
android:layout_height="wrap_content"
34-
android:id="@+id/normal"
35-
app:text="@string/continue_text"
36-
app:textColor="@color/white"
37-
app:progressColor="@color/black"
38-
app:progressBarSize="small"
39-
app:layout_constraintTop_toTopOf="parent"
40-
app:layout_constraintStart_toStartOf="parent"
41-
android:layout_marginTop="28dp"
42-
app:layout_constraintEnd_toEndOf="parent"
43-
android:layout_marginEnd="8dp"
44-
android:layout_marginRight="8dp"
45-
android:layout_marginLeft="8dp"
46-
android:layout_marginStart="8dp"/>
31+
<com.droidbond.loadingbutton.LoadingButton
32+
android:layout_width="wrap_content"
33+
android:layout_height="wrap_content"
34+
app:text="Custom Button"
35+
app:background="@color/colorAccent"
36+
app:successBackground="@drawable/ic_bg_blue_buttons_style"
37+
app:successIcon="@drawable/ic_done_white_24dp"
38+
app:textSize="16sp"
39+
app:boldText="true"
40+
app:textColor="@color/black"
41+
app:progressColor="@color/black"
42+
app:progressBarSize="small"
43+
android:id="@+id/custombtn"
44+
app:layout_constraintStart_toStartOf="parent"
45+
android:layout_marginTop="20dp"
46+
app:layout_constraintTop_toBottomOf="@+id/normal"
47+
app:layout_constraintEnd_toEndOf="parent"
48+
android:layout_marginEnd="8dp"
49+
android:layout_marginRight="8dp"
50+
android:layout_marginStart="8dp"
51+
android:layout_marginLeft="8dp"/>
4752
```
4853
### Customizable attributes
4954
```xml
50-
<attr name="text" format="string"/>
51-
<attr name="textColor" format="color"/>
52-
<attr name="boldText" format="boolean"/>
53-
<attr name="textSize" format="dimension"/>
54-
<attr name="progressColor" format="color"/>
55-
<attr name="customFontFamily" format="reference"/>
56-
<attr name="background" format="reference"/>
57-
<attr name="progressBarSize" format="enum">
58-
<enum name="large" value="64"/>
59-
<enum name="medium" value="48"/>
60-
<enum name="small" value="18"/>
61-
</attr>
55+
<attr name="text" format="string"/>
56+
<attr name="textColor" format="color"/>
57+
<attr name="boldText" format="boolean"/>
58+
<attr name="textSize" format="dimension"/>
59+
<attr name="progressColor" format="color"/>
60+
<attr name="background" format="reference"/>
61+
<attr name="successBackground" format="reference"/>
62+
<attr name="errorBackground" format="reference"/>
63+
<attr name="successIcon" format="reference"/>
64+
<attr name="errorIcon" format="reference"/>
65+
<attr name="customFontFamily" format="reference"/>
66+
<attr name="progressBarSize" format="enum">
67+
<enum name="large" value="64"/>
68+
<enum name="medium" value="48"/>
69+
<enum name="small" value="18"/>
70+
</attr>
6271
```
6372
```java
6473
LoadingButton custombtn = findViewById(R.id.custombtn);
@@ -79,9 +88,9 @@ custombtn.showSuccess()
7988
```java
8089
custombtn.showError()
8190
```
82-
### Loading?
91+
### Loading status
8392
```java
8493
custombtn.isLoading()
8594
```
8695

87-
For a complete example see the sample app https://github.com/droidbond/LoadingButton/tree/master/app
96+
For a complete example, see the [sample app] (LoadingButton/tree/master/app)

app/src/main/res/layout/activity_main.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
android:layout_width="wrap_content"
1212
android:layout_height="wrap_content"
1313
android:id="@+id/normal"
14+
app:errorBackground="@drawable/ic_bg_red_buttons_style"
15+
app:errorIcon="@drawable/ic_warning"
1416
app:layout_constraintTop_toTopOf="parent"
1517
app:layout_constraintStart_toStartOf="parent"
1618
android:layout_marginTop="28dp"
@@ -25,6 +27,8 @@
2527
android:layout_height="wrap_content"
2628
app:text="Custom Button"
2729
app:background="@color/colorAccent"
30+
app:successBackground="@drawable/ic_bg_blue_buttons_style"
31+
app:successIcon="@drawable/ic_done_white_24dp"
2832
app:textSize="16sp"
2933
app:boldText="true"
3034
app:textColor="@color/black"

loadingbutton/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111
minSdkVersion 15
1212
targetSdkVersion 28
1313
versionCode 6
14-
versionName "0.1.6"
14+
versionName "0.1.7"
1515

1616
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1717

loadingbutton/src/main/java/com/droidbond/loadingbutton/LoadingButton.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class LoadingButton @JvmOverloads constructor(
4343
private lateinit var tvText: TextView
4444
private var array: TypedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.app, defStyleAttr, 0)
4545
private var bg: Int = R.drawable.ic_bg_blue_buttons_style
46+
private var successBg: Int = R.drawable.ic_bg_blue_buttons_style
47+
private var errorBg: Int = R.drawable.ic_bg_red_buttons_style
48+
private var successIcon: Int = R.drawable.ic_done_white_24dp
49+
private var errorIcon: Int = R.drawable.ic_warning
4650

4751
init {
4852
initView()
@@ -64,14 +68,14 @@ class LoadingButton @JvmOverloads constructor(
6468
*/
6569
fun showSuccess() {
6670
tvText.visibility = View.INVISIBLE
67-
view.setBackgroundResource(bg)
71+
view.setBackgroundResource(successBg)
6872

6973
if (Build.VERSION.SDK_INT >= 19) {
7074
TransitionManager.beginDelayedTransition(view as ViewGroup, Fade(Fade.IN))
7175
}
7276
progressBar.visibility = View.INVISIBLE
7377
img.visibility = View.VISIBLE
74-
img.setImageResource(R.drawable.ic_done_white_24dp)
78+
img.setImageResource(successIcon)
7579
}
7680

7781
/**
@@ -80,15 +84,15 @@ class LoadingButton @JvmOverloads constructor(
8084
fun showError() {
8185
tvText.visibility = View.INVISIBLE
8286

83-
view.setBackgroundResource(R.drawable.ic_bg_red_buttons_style)
87+
view.setBackgroundResource(errorBg)
8488

8589
if (Build.VERSION.SDK_INT >= 19) {
8690
TransitionManager.beginDelayedTransition(view as ViewGroup, Fade(Fade.IN))
8791
}
8892

8993
progressBar.visibility = View.INVISIBLE
9094
img.visibility = View.VISIBLE
91-
img.setImageResource(R.drawable.ic_warning)
95+
img.setImageResource(errorIcon)
9296
}
9397

9498
/**
@@ -134,6 +138,20 @@ class LoadingButton @JvmOverloads constructor(
134138
setBackgroundResource(customBg)
135139
bg = customBg
136140
}
141+
142+
if (array.getResourceId(R.styleable.app_successBackground, 0) != 0) {
143+
successBg = array.getResourceId(R.styleable.app_successBackground, 0)
144+
}
145+
if (array.getResourceId(R.styleable.app_errorBackground, 0) != 0) {
146+
errorBg = array.getResourceId(R.styleable.app_errorBackground, 0)
147+
}
148+
149+
if (array.getResourceId(R.styleable.app_successIcon, 0) != 0) {
150+
successIcon = array.getResourceId(R.styleable.app_successIcon, 0)
151+
}
152+
if (array.getResourceId(R.styleable.app_errorIcon, 0) != 0) {
153+
errorIcon = array.getResourceId(R.styleable.app_errorIcon, 0)
154+
}
137155
}
138156
}
139157

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
<vector android:autoMirrored="true" android:height="24dp"
2-
android:viewportHeight="44" android:viewportWidth="312"
3-
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4-
<path android:fillColor="#007AD0" android:fillType="evenOdd" android:pathData="M0,3C0,1.343 1.343,0 3,0H309C310.657,0 312,1.343 312,3V41C312,42.657 310.657,44 309,44H3C1.343,44 0,42.657 0,41V3Z"/>
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true"
2+
android:height="24dp" android:viewportHeight="44"
3+
android:viewportWidth="312" android:width="24dp">
4+
<path android:fillColor="#007AD0" android:fillType="evenOdd"
5+
android:pathData="M0,3C0,1.343 1.343,0 3,0H309C310.657,0 312,1.343 312,3V41C312,42.657 310.657,44 309,44H3C1.343,44 0,42.657 0,41V3Z"/>
56
</vector>
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
<vector android:autoMirrored="true" android:height="24dp"
2-
android:viewportHeight="44" android:viewportWidth="312"
3-
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4-
<path android:fillColor="#ffff4444" android:fillType="evenOdd" android:pathData="M0,3C0,1.343 1.343,0 3,0H309C310.657,0 312,1.343 312,3V41C312,42.657 310.657,44 309,44H3C1.343,44 0,42.657 0,41V3Z"/>
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true"
2+
android:height="24dp" android:viewportHeight="44"
3+
android:viewportWidth="312" android:width="24dp">
4+
<path android:fillColor="#ffff4444" android:fillType="evenOdd"
5+
android:pathData="M0,3C0,1.343 1.343,0 3,0H309C310.657,0 312,1.343 312,3V41C312,42.657 310.657,44 309,44H3C1.343,44 0,42.657 0,41V3Z"/>
56
</vector>

loadingbutton/src/main/res/values/styles.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<attr name="textSize" format="dimension"/>
88
<attr name="progressColor" format="color"/>
99
<attr name="background" format="reference"/>
10+
<attr name="successBackground" format="reference"/>
11+
<attr name="errorBackground" format="reference"/>
12+
<attr name="successIcon" format="reference"/>
13+
<attr name="errorIcon" format="reference"/>
1014
<attr name="customFontFamily" format="reference"/>
1115
<attr name="progressBarSize" format="enum">
1216
<enum name="large" value="64"/>

0 commit comments

Comments
 (0)