3

在 Anko 的警报生成器中使用positiveButtonandnegativeButton时,似乎它们都导致关闭对话框,即使dismiss()没有被调用。单击按钮后有什么方法可以使对话框保持打开状态(如果有positiveButton/以外的类型negativeButton也可以)?

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

2 回答 2

7

对于将来可能遇到此问题的任何人,这就是您可以在 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()
    }
于 2017-08-15T15:39:39.720 回答
-1
alert {
  title = "Add Board"
  customView {
    ....
  }
  positiveButton("OK") { /*Keep blank, we'll override it later*/}
  negativeButton("Close"){}

  isCancelable = false // Disable close here
}.show()
于 2019-01-04T17:05:47.473 回答