Skip to content

MaterialAlertDialogCentered

Leonardo D. Palma edited this page Mar 27, 2025 · 8 revisions

Create and display a dialog box with elements centered on the dialog container.

Usage

MaterialAlertDialogCentered

In code:

MaterialAlertDialogCentered.Builder(applicationContext)
            .setIcon(R.drawable.ic_resource)
            .setTitle("Lorem Ipsum")
            .setMessage("What is Lorem Ipsum?")
            .setCancelable(false)
            .setPositiveButton(ButtonIconAlert(R.drawable.ic_resource), object : DialogAlertInterface.OnClickListener {
                override fun onClick(dialog: DialogAlertInterface, whichButton: DialogAlertInterface.UI) {
                    TODO("Not yet implemented")
                }
            })
            .create()
            .show()

Attributes

MaterialAlertDialogCentered 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()
Animation Set the json animation resource to be used on the icon Int N/A setAnimation()
Image Set the drawable resource to be used in the icon Int N/A setImage()
Icon Set the drawable resource to be used in the icon Int N/A setIcon()
Icon Background Tint Set background tint for icon Int or rgb(R,G,B) N/A setIconBackgroundTint()
Icon Background Tint Set background tint for icon IntRes N/A setIconBackgroundTintRes()
Title Set the title displayed String, Int N/A setTitle()
Message Sets the message to display String, Int N/A setMessage()
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()
Count Down Timer Set a countdown on one of the buttons (DialogAlertInterface.UI, Long) N/A setCountDownTimer()
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 MaterialAlertDialogCentered 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