Skip to content

Commit c26df65

Browse files
authored
Merge pull request #5 from umairayub79/NewMethods
Added two new methods **.setPositiveButtonTextColor(int) **.setNegativeButtonTextColor(int)
2 parents 1cc3229 + 39725a4 commit c26df65

File tree

5 files changed

+74
-16
lines changed

5 files changed

+74
-16
lines changed

.idea/jarRepositories.xml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ dependencies {
7676
.setBackgroundColor(int);
7777
.setNegativeButtonText(String);
7878
.setPositiveButtonText(String);
79+
.setPositiveButtonTextColor(int)
80+
.setNegativeButtonTextColor(int)
7981
.setCancelableOnOutsideTouch(boolean);
8082
.setPositiveButtonListener(MaDialogListener);
8183
.setNegativeButtonListener(MaDialogListener);
8284
.build();
85+
8386
```

app/src/main/java/umairayub/madialogdemoapp/MainActivity.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,25 @@ class MainActivity : AppCompatActivity() {
6565
MaDialog.Builder(this@MainActivity)
6666
.setTitle("Basic with Image + Title + Buttons")
6767
.setMessage(msg)
68-
.setBackgroundColor(Color.parseColor("#B71C1C"))
68+
.setMessageTextColor(Color.WHITE)
69+
.setTitleTextColor(Color.WHITE)
70+
.setBackgroundColor(Color.BLUE)
71+
.setPositiveButtonTextColor(Color.GREEN)
72+
.setNegativeButtonTextColor(Color.RED)
6973
.setImage(R.drawable.image)
70-
.AddNewButton(R.style.AppTheme, "Yes", object : MaDialogListener {
74+
.setPositiveButtonText("Yes")
75+
.setNegativeButtonText("No")
76+
.setPositiveButtonListener(object : MaDialogListener {
7177
override fun onClick() {
7278

7379
}
7480
})
75-
.AddNewButton(R.style.AppTheme, "Cancel", object : MaDialogListener {
81+
.setNegativeButtonListener(object : MaDialogListener {
7682
override fun onClick() {
7783

7884
}
7985
})
86+
8087
.build()
8188
}
8289
btn6.setOnClickListener {

madialog/src/main/java/umairayub/madialog/MaDialog.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class MaDialog {
3232
private var negativeButtonText: String? = null
3333

3434
private var buttonTextColor: Int = 0
35+
private var positiveButtonTextColor: Int = 0
36+
private var negativeButtonTextColor: Int = 0
3537
private var messageTextColor: Int = 0
3638
private var titleTextColor: Int = 0
3739
private var backgroundColor: Int = 0
@@ -85,6 +87,16 @@ class MaDialog {
8587
return this
8688
}
8789

90+
fun setPositiveButtonTextColor(positiveButtonTextColor: Int): Builder {
91+
this.positiveButtonTextColor = positiveButtonTextColor
92+
return this
93+
}
94+
95+
fun setNegativeButtonTextColor(negativeButtonTextColor: Int): Builder {
96+
this.negativeButtonTextColor = negativeButtonTextColor
97+
return this
98+
}
99+
88100
fun setCancelableOnOutsideTouch(cancelOnOutsideTouch: Boolean): Builder {
89101
this.cancelOnOutsideTouch = cancelOnOutsideTouch
90102
return this
@@ -206,6 +218,16 @@ class MaDialog {
206218
if (buttonTextColor != 0) {
207219
btnNegative.setTextColor(buttonTextColor)
208220
btnPositve.setTextColor(buttonTextColor)
221+
for (i in buttons.indices) {
222+
buttons[i].setTextColor(buttonTextColor)
223+
}
224+
225+
}
226+
if (positiveButtonTextColor != 0) {
227+
btnPositve.setTextColor(positiveButtonTextColor)
228+
}
229+
if (negativeButtonTextColor != 0) {
230+
btnNegative.setTextColor(negativeButtonTextColor)
209231
}
210232
if (negativeButtonText != null) {
211233
btnNegative.text = negativeButtonText

madialog/src/main/res/layout/madialog.xml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,51 @@
3030
android:id="@+id/tvTitleDisplay"
3131
android:layout_width="wrap_content"
3232
android:layout_height="wrap_content"
33+
android:gravity="center_horizontal"
3334
android:paddingStart="16dp"
3435
android:paddingTop="20dp"
3536
android:paddingEnd="16dp"
3637
android:paddingBottom="20dp"
3738
android:textAlignment="center"
3839
android:textSize="18sp"
3940
android:textStyle="bold"
40-
android:visibility="gone"
41-
android:gravity="center_horizontal" />
41+
android:visibility="gone" />
4242

4343
<TextView
44-
android:layout_margin="10dp"
4544
android:id="@+id/tvMessageDisplay"
4645
android:layout_width="wrap_content"
4746
android:layout_height="wrap_content"
48-
android:textAlignment="center"
49-
android:visibility="gone"
50-
android:paddingEnd="16dp"
47+
android:layout_margin="10dp"
48+
android:gravity="center_horizontal"
5149
android:paddingStart="16dp"
52-
android:gravity="center_horizontal" />
50+
android:paddingEnd="16dp"
51+
android:textAlignment="center"
52+
android:visibility="gone" />
5353

5454
<LinearLayout
5555
android:id="@+id/buttonLayout"
56-
android:layout_marginBottom="8dp"
57-
android:layout_marginEnd="8dp"
58-
android:layout_marginTop="8dp"
59-
android:layout_marginStart="8dp"
6056
android:layout_width="match_parent"
6157
android:layout_height="wrap_content"
6258
android:layout_gravity="center"
59+
android:layout_marginStart="8dp"
60+
android:layout_marginTop="8dp"
61+
android:layout_marginEnd="8dp"
62+
android:layout_marginBottom="8dp"
6363
android:gravity="center"
6464
android:orientation="horizontal">
6565

6666
<Button
6767
android:id="@+id/btn_positive"
68-
android:background="@android:color/transparent"
6968
android:layout_width="wrap_content"
7069
android:layout_height="wrap_content"
70+
android:background="@android:color/transparent"
7171
android:visibility="gone" />
72+
7273
<Button
7374
android:id="@+id/btn_negative"
74-
android:background="@android:color/transparent"
7575
android:layout_width="wrap_content"
7676
android:layout_height="wrap_content"
77+
android:background="@android:color/transparent"
7778
android:visibility="gone" />
7879
</LinearLayout>
7980
</LinearLayout>

0 commit comments

Comments
 (0)