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

问题描述:

在Anko的警报构建器中使用positiveButtonnegativeButton时,即使未调用dismiss(),似乎它们都会导致关闭对话框。单击按钮后是否有任何方法保持对话框打开(如果存在positiveButton/negativeButton以外的其他类型,那也可以)?Kotlin/Anko防止按钮关闭警报对话框

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

做到这一点我想这是Android的AlertDialog的默认行为。 – Bob

+0

@鲍勃啊,没有意识到。我会看看是否有方法来覆盖 – Parker

+1

检查此答案:https://stackoverflow.com/a/7636468/4586742 – Bob

对于任何可能在将来有这个问题,这就是如何在科特林

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