Skip to content

MaterialAlertDialogVerificationCode

Leonardo D. Palma edited this page Aug 26, 2025 · 14 revisions

Create and display a code validation dialog box with n-digit, and you can add additional information.

Usage

MaterialAlertDialogVerificationCode

In code:

MaterialAlertDialogVerificationCode.Builder(applicationContext)
            .setIcon(R.drawable.ic_resource)
            .setTitle("Lorem Ipsum")
            .setMessage("What is Lorem Ipsum?")
            .setMessageOTP("Ingrese el código continuación")
            .setCancelable(false)
            .setPositiveButton(object : DialogAlertInterface.OnClickVerificationCodeListener {
                override fun onClick(dialog: DialogAlertInterface, code: String, reason: String?, firstInput: String?, secondInput: String?) {
                    TODO("Not yet implemented")
                }
            })
            .setNegativeButton(ButtonIconAlert(R.drawable.ic_resource), object : DialogAlertInterface.OnClickListener {
                override fun onClick(dialog: DialogAlertInterface, whichButton: DialogAlertInterface.UI) {
                    TODO("Not yet implemented")
                }
            })
            .create()
            .show()

Type Extras

  • DEFAULT_MASKED values is [A-Z0-9]*. Only allow capital letters and numbers

  • 2 additional entries can be added to the dialog. Which are specified below

InputCodeExtra

Attributes

MaterialAlertDialogVerificationCode 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()
Icon Tint Color Set background tint for icon Int or rgb(R,G,B) N/A setIconTintColor()
Icon Tint Color Set background tint for icon IntRes N/A setIconTintColorRes()
Title Set the title displayed String, Int N/A setTitle()
Message Sets the message to display String, Int N/A setMessage()
Message OTP Sets the message to display String, Int N/A setMessageOTP()
NeedReason Specify the reason for the action Boolean true setNeedReason()
Cancelable Sets whether the dialog is cancelable or not Boolean false setCancelable()
Code Text Length Set input code length Int 4 setInputCodeLength()
Code Text Mask Set input code mask String DEFAULT_MASKED setInputCodeMask()
Code Text Visible Sets whether text input code is visible or not Boolean true setInputCodeTextVisible()
Show Icon Sets whether the dialog icon should be displayed Boolean true setShowIcon()
Message OTP Visible Sets whether the OTP code message is visible or not Boolean true setMessageOTPVisible()
Box Corner Set the corner radius of the TextInputLayout float 10f setBoxCornerRadius()
First Input Add input text InputCodeExtra N/A setInputFirstExtra()
Second Input Add input text InputCodeExtra N/A setInputSecondExtra()
Gravity Set gravity of the dialog Int [android.view.Gravity] N/A setGravity()
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()
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 MaterialAlertDialogVerificationCode 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