2017-08-15 151 views
1

在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

回答

3

對於任何可能在將來有這個問題,這就是如何在科特林

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() 
    } 
相關問題