Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Afollestad Material Dialog action button text color

I have been using a library called material-dialogs by afollestad. I need to change the text color of the positive and negative button action.

MaterialDialog(this).show {
            positiveButton("yes") {
                clearData()
                goToLoginPage()
            }
            negativeButton("cancel") { dismiss() }
            message("Some message")
        }

The above is the code for showing the material dialog. For the button arguments only the title of the button could be given. My requirement is to change 'yes' to green text color and 'cancel' to red text color. Is it possible to achieve using this library?

like image 918
Anand A Avatar asked Dec 17 '22 18:12

Anand A


1 Answers

Ok here are the three lines you can override in your AppTheme inside styles.xml to give it your own colors.

To Change Dialog Title Color

<item name="md_color_title">@color/yourTitleColor</item>

To Change Dialog Content Color

<item name="md_color_content">@color/yourContentColor</item>

To Change Dialog Positive and Negative Button Colors

<item name="md_color_button_text">@color/yourPositiveNegativeColor</item>

To Change Dialog Background Color

<item name="md_background_color">@color/yourDialogBgColor</item>

To Change Dialog Divider Color

<item name="md_divider_color">@color/yourDialogDividerColor</item>

EDIT:

As OP told that he wants to give different colors for Positive and Negative buttons there seems no solution in the library but we can use a work around given below. By using java method Html.from where we can set our own color for each button text.

val yesText = "<font color='#1B1ED8'>Yes</font>"
val cancelText = "<font color='#44D81B'>Cancel</font>"

MaterialDialog(this).show {
    positiveButton(text = Html.fromHtml(yesText))
    negativeButton(text = Html.fromHtml(cancelText))
    message(R.string.Some_message)
}
like image 149
Abid Khan Avatar answered Dec 21 '22 11:12

Abid Khan