0
1

More than 3 years have passed since last update.

【Kotlin 初心者】ダイアログの作成方法

Posted at

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()
        }
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1