-
Notifications
You must be signed in to change notification settings - Fork 1
MaterialAlertDialogEvents
Leonardo D. Palma edited this page Mar 27, 2025
·
16 revisions
Create and display a dialog box to notify if actions taken have positive or negative results.
In code:
MaterialAlertDialogEvents.Builder(applicationContext)
.setIcon(R.drawable.ic_resource)
.setBackgroundColorSpan(60, 100, 200)
.setTitle("Lorem Ipsum")
.setMessage("What is Lorem Ipsum?")
.setDetails("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
.setCancelable(false)
.setPositiveButton(object : MaterialDialogInterface.OnClickListener {
override fun onClick(dialog: DialogAlertInterface, whichButton: DialogAlertInterface.UI) {
TODO("Not yet implemented")
}
})
.setNeutralButton(object : MaterialDialogInterface.OnClickListener {
override fun onClick(dialog: DialogAlertInterface, whichButton: DialogAlertInterface.UI) {
TODO("Not yet implemented")
}
})
.setNegativeButton(ButtonIconAlert(R.drawable.ic_resource), object : MaterialDialogInterface.OnClickListener {
override fun onClick(dialog: DialogAlertInterface, whichButton: DialogAlertInterface.UI) {
TODO("Not yet implemented")
}
})
.create()
.show()There are different types you can use.
-
Alert.State.CUSTOMShows the icon without predefined elements. Configure it to your style. -
Alert.State.DELETEShows the half triangle in blue with an delete icon. -
Alert.State.ERRORShows the half triangle in red with an error icon. -
Alert.State.HELPDisplays the half triangle in secondaryColor with a help icon. -
Alert.State.INFORMATIONDisplays the half triangle in primaryColor with an information icon. -
Alert.State.SUCCESSShows the half triangle in green with a check icon. -
Alert.State.WARNINGShows the half triangle in yellow with a warning icon. -
Alert.State.WITHOUT_INTERNETShows the half triangle in orange with a cloud icon. -
Alert.State.WITHOUT_INTERNET_MOBILEShows the half triangle in orange with a mobile alert icon. -
Alert.State.WITHOUT_INTERNET_WIFIShows the half triangle in orange with a wifi alert icon.
MaterialAlertDialogEvents offers several attributes for a deeper view configuration, the following table shows all these options and their default value.
| Name | Description | Values | Default | Related method(s) |
|---|---|---|---|---|
| Builder | Creates a builder for an alert dialog that uses the default alert dialog theme | Context |
N/A | Builder() |
| Icon | Set the drawable resource to be used in the icon | Int |
R.mipmap.ic_launcher_round |
setIcon() |
| BackgroundColorSpan | Set the color of the circle at the beginning of the dialog |
Int or rgb(R,G,B)
|
N/A | setBackgroundColorSpan() |
| BackgroundColorSpan | Set the color of the circle at the beginning of the dialog | Int |
N/A | setBackgroundColorSpanRes() |
| MessageSpanLengthMax | Set the maximum number of letters | Int |
200 |
setMessageSpanLengthMax() |
| DetailsScrollHeightSpan | Set the maximum scroll size | Int |
400 |
setDetailsScrollHeightSpan() |
| Count Down Timer | Set a countdown on one of the buttons | (DialogAlertInterface.UI, Long) |
N/A | setCountDownTimer() |
| Type | Set material dialog type | Alert.State |
Alert.State.CUSTOM |
setType() |
| Title | Set the title displayed |
String, Int
|
N/A | setTitle() |
| Message | Sets the message to display |
String, Int
|
N/A | setMessage() |
| Details | Sets the details to display |
String, Int
|
N/A | setDetails() |
| Gravity | Set gravity of the dialog |
Int [android.view.Gravity] |
N/A | setGravity() |
| Cancelable | Sets whether the dialog is cancelable or not | Boolean |
true |
setCancelable() |
| PositiveButton | Set a listener to be invoked when the positive button of the dialog is pressed |
null, String or Int
|
N/A | setPositiveButton() |
| NeutralButton | Set a listener to be invoked when the neutral button of the dialog is pressed |
null, String or Int
|
N/A | setNeutralButton() |
| NegativeButton | Set a listener to be invoked when the negative button of the dialog is pressed |
null, String or Int
|
N/A | setNegativeButton() |
| create | Creates an MaterialAlertDialogEvents with the arguments supplied to this builder | - | - | create() |
| show | Start the dialog and display it on screen | - | - | show() |
If you want to add more functionality to dialog events, you can use the following methods to capture the actions.
- When the
dismissoption is called from the dialog box, you can use thesetOnDismissListenermethod to perform additional actions. - When the
canceloption is called from the dialog box, you can use thesetOnCancelListenermethod to perform additional actions. - When the
showoption is called from the dialog box, you can use thesetOnShowListenermethod to perform additional actions.