facebook twitter hatena line email

「Android/kotlin/Alert」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ok,cancelの2択)
行22: 行22:
 
     .show()
 
     .show()
 
</pre>
 
</pre>
 +
 +
==枠外クリックでキャンセル防止==
 +
setCancelable(false)を追加
 +
<pre>
 +
AlertDialog.Builder(this)
 +
    .setCancelable(false)
 +
</pre>
 +
参考:http://nishi.sunnyday.jp/Knowledge/Android/tips/AlertDialog/setCancelable

2020年3月31日 (火) 14:41時点における版

okのみ

AlertDialog.Builder(context)
    .setTitle("タイトル1")
    .setMessage("文章1")
    .setPositiveButton("OK") { dialog, which ->
        Log.i("AlertDialog", "OK")
    }
    .show()

ok,cancelの2択

AlertDialog.Builder(context)
    .setTitle("タイトル1")
    .setMessage("文章1")
    .setPositiveButton("OK") { dialog, which ->
        Log.i("AlertDialog", "OK")
    }
    .setNegativeButton("Cancel"){ dialog, which ->
        Log.i("AlertDialog", "Cancel")
    }
    .show()

枠外クリックでキャンセル防止

setCancelable(false)を追加

 AlertDialog.Builder(this)
     .setCancelable(false)

参考:http://nishi.sunnyday.jp/Knowledge/Android/tips/AlertDialog/setCancelable