How do I display an alert dialog on Android?

后端 未结 30 3063
清歌不尽
清歌不尽 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:27

    This is done in kotlin

    val builder: AlertDialog.Builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert)
            } else {
                AlertDialog.Builder(this)
            }
            builder.setTitle("Delete Alert!")
                    .setMessage("Are you want to delete this entry?")
                    .setPositiveButton("YES") { dialog, which ->
    
                    }
                    .setNegativeButton("NO") { dialog, which ->
    
                    }
                    .setIcon(R.drawable.ic_launcher_foreground)
                    .show()
    

提交回复
热议问题