如何在Android的模式对话框对话框、模式、如何在、Android

2023-09-05 01:09:15 作者:月白流苏谨色安年

我要为我的应用程序中创建模式对话框。

i want create modal dialog box for my application.

所以,当模式对话框打开其他活动都被阻止。任何情况下都做过这样的后退按钮preSS或home键preSS。

so when modal dialog box open the other activities are blocked. no event are done like back button press or home button press.

,并把该对话框中的两个可选按钮来取消和确定。

and put two option button in that dialog box cancel and ok.

感谢您......

推荐答案

有许多种对话框的Andr​​oid系统。请看看对话框。我猜你正在寻找的是类似 AlertDialog 。这是如何对返回preSS 按钮实现的例子。

There are many kind of Dialogs in Android. Please take a look at Dialogs. I guess what you are looking for is something like AlertDialog . This is the example of how you can implement on BackPress button.

@Override
public void onBackPressed() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Do you want to logout?");
    // alert.setMessage("Message");

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            //Your action here
        }
    });

    alert.setNegativeButton("Cancel",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });

    alert.show();

}
 
精彩推荐