Skip to content

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.

Usage

MaterialAlertDialogEvents

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()

Types

There are different types you can use.

  1. Alert.State.CUSTOM Shows the icon without predefined elements. Configure it to your style.
  2. Alert.State.DELETE Shows the half triangle in blue with an delete icon.
  3. Alert.State.ERROR Shows the half triangle in red with an error icon.
  4. Alert.State.HELP Displays the half triangle in secondaryColor with a help icon.
  5. Alert.State.INFORMATION Displays the half triangle in primaryColor with an information icon.
  6. Alert.State.SUCCESS Shows the half triangle in green with a check icon.
  7. Alert.State.WARNING Shows the half triangle in yellow with a warning icon.
  8. Alert.State.WITHOUT_INTERNET Shows the half triangle in orange with a cloud icon.
  9. Alert.State.WITHOUT_INTERNET_MOBILE Shows the half triangle in orange with a mobile alert icon.
  10. Alert.State.WITHOUT_INTERNET_WIFI Shows the half triangle in orange with a wifi alert icon.

Attributes

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 dismiss option is called from the dialog box, you can use the setOnDismissListener method to perform additional actions.
  • When the cancel option is called from the dialog box, you can use the setOnCancelListener method to perform additional actions.
  • When the show option is called from the dialog box, you can use the setOnShowListener method to perform additional actions.

Clone this wiki locally