Kotlin / Anko阻止按钮关闭警报对话框

时间:2017-08-15 15:25:20

标签: android kotlin android-alertdialog anko

在Anko的警报构建器中使用positiveButtonnegativeButton时,即使未调用dismiss(),它们似乎也会导致关闭对话框。有没有办法在点击按钮后保持对话框打开(如果有positiveButton / negativeButton以外的类型,那也很好)?

alert {
    title = "Add Board"
    customView {
        ....
    }
    positiveButton("OK") { doSomeFunction() }
    negativeButton("Close"){}
}.show()

2 个答案:

答案 0 :(得分:5)

对于将来可能遇到此问题的任何人,您可以在Kotlin中完成此任务

val myAlert = alert {
    title = "Add Board"
    customView {
        ....
    }
    positiveButton("OK") { /*Keep blank, we'll override it later*/}
    negativeButton("Close"){}
    }.show()

//You can use BUTTON_NEGATIVE and BUTTON_NEUTRAL for other buttons
(myAlert as AlertDialog).getButton(AlertDialog.BUTTON_POSITIVE)
    .setOnclickListener{
        doSomeFunction()
    }

答案 1 :(得分:0)

alert {
  title = "Add Board"
  customView {
    ....
  }
  positiveButton("OK") { /*Keep blank, we'll override it later*/}
  negativeButton("Close"){}

  isCancelable = false // Disable close here
}.show()