在Anko的警报构建器中使用positiveButton
和negativeButton
时,即使未调用dismiss()
,它们似乎也会导致关闭对话框。有没有办法在点击按钮后保持对话框打开(如果有positiveButton
/ negativeButton
以外的类型,那也很好)?
alert {
title = "Add Board"
customView {
....
}
positiveButton("OK") { doSomeFunction() }
negativeButton("Close"){}
}.show()
答案 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()