Kotlinでダイアログを表示する方法
簡単にですがダイアログを表示する実装になります。
今回はButtonをタップした時にダイアログを表示する想定のコードになります。
MainActiviy.kt
val button = findViewById<Button>(R.id.button)
button.setOnClickListener {
AlertDialog.Builder(context)
.setTitle("ダイアログのタイトルをいれう")
.setPositiveButton("OK", { dialog, which ->
//OKの時の処理
})
.setNegativeButton("No", { dialog, which ->
//NOの時の処理
})
.show()
}