-5

Snackbar.make(findViewById(android.R.id.content),"Restart to update", Snackbar.LENGTH_INDEFINITE)

i want change this to alert dialog, need help

ADM
  • 20,406
  • 11
  • 52
  • 83
  • 1
    Please do some research before posting question . There is no magic Stick to convert component one to another . You need to create one . – ADM Oct 21 '20 at 05:43

1 Answers1

0

You can find the official documentation here

To implement an AlertDialog you need to use the AlertDialog.Builder class too setup the AlertDialog. Then you can use the .create() method to create the AlertDialog, and then finally .show() of AlertDialog class to show the dialog.

val alertDialog: AlertDialog? = activity?.let {
    val builder = AlertDialog.Builder(it)
    builder.apply {
        setMessage("This is the message")
        setTitle("This is the title")
        setPositiveButton(R.string.ok,
                DialogInterface.OnClickListener { dialog, id ->
                    // User clicked OK button
                })
        setNegativeButton(R.string.cancel,
                DialogInterface.OnClickListener { dialog, id ->
                    // User cancelled the dialog
                    // Use this to dismiss dialog
                    dialog.dismiss()
                })
    }
    // Set other dialog properties
    ...

    // Create the AlertDialog
    builder.create()
}

alertDialog.show()

You can use this to dismiss the dialog:

alertDialog.dismiss()
yusufpats
  • 778
  • 4
  • 12