How do I display an alert dialog on Android?

后端 未结 30 2534
清歌不尽
清歌不尽 2020-11-22 03:02

I want to display a dialog/popup window with a message to the user that shows \"Are you sure you want to delete this entry?\" with one button that says \'Delete\'. When

30条回答
  •  攒了一身酷
    2020-11-22 03:31

    Simplest Solution For Kotln Developers

    val alertDialogBuilder: AlertDialog.Builder = AlertDialog.Builder(requireContext())
        alertDialogBuilder.setMessage(msg)
        alertDialogBuilder.setCancelable(true)
    
        alertDialogBuilder.setPositiveButton(
            getString(android.R.string.ok)
        ) { dialog, _ ->
            dialog.cancel()
        }
    
        val alertDialog: AlertDialog = alertDialogBuilder.create()
        alertDialog.show()
    

提交回复
热议问题