古詩詞大全網 - 成語查詢 - android中如何在對話框中按鈕實現返回鍵的功能。就是關閉當前對話框返回上壹個界面。

android中如何在對話框中按鈕實現返回鍵的功能。就是關閉當前對話框返回上壹個界面。

直接給妳貼代碼了。這樣直接壹些兄弟。

new AlertDialog.Builder(activity)

.setMessage(R.string.title_cancel_alertdialog)

.setPositiveButton(“確認”, new DialogInterface.OnClickListener() {//確認按鈕

public void onClick(DialogInterface arg0, int arg1) {

//按鈕點擊後觸發的動作,點擊後對話框是自動消失的

}

})

.setNegativeButton("取消", new DialogInterface.OnClickListener() {//取消按鈕

public void onClick(DialogInterface arg0, int arg1) {

//按鈕點擊後觸發的動作,點擊後對話框是自動消失的

}

}).show();