在我的应用程序中,我使用了一个按钮单击警报对话框生成器。所以当我按下一个按钮,小弹出窗口打开选项-激活和停用。所以我能确保当用户按下激活或停用时,确认窗口将打开并询问您是否确定?还有一个选择是还是不是?是吗?

最佳答案

我在另一个对话框中创建了对话框。
请参阅以下代码:

twsbiSelectionMenuDialog = new Dialog(this,R.style.CustomDialogTheme);
            twsbiSelectionMenuDialog.setContentView(R.layout.twsbi_selection_menu_dialog);
            twsbiSelectionMenuDialog.setCancelable(true);
            twsbiSelectionMenuDialog.setCanceledOnTouchOutside(true);

            // To Open new Canvas ===================================
            Button newLayoutButton = (Button) twsbiSelectionMenuDialog.findViewById(R.id.newLayoutButton);
            newLayoutButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    twsbiSelectionMenuDialog.dismiss();
                    // AlertDialog for confirmation
                    AlertDialog.Builder clearConfirmDialog = new AlertDialog.Builder(TWSBIDrawMainActivity.this);
                    clearConfirmDialog.setMessage("Do you want to clear this and open new canvas ?").setCancelable(false)
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // Action for 'Yes' Button
                            myView = new MyView(TWSBIDrawMainActivity.this);
                            takePhotoFromCamera = false;
                            takePhotoFromGallery = false;
                            canvasColor = 0xFFFFFFFF;
                            drawingLayout.removeView(myView);
                            drawingLayout.addView(myView);
                        }
                    })
                    .setNegativeButton("No", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            //  Action for 'NO' Button
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = clearConfirmDialog.create();
                    alert.setTitle("Draw");
                    alert.setIcon(R.drawable.app_icon);
                    alert.show();
                }
            });

            // For canvas Color Selection ===================================
            Button canvasColorButton = (Button) twsbiSelectionMenuDialog.findViewById(R.id.canvasColorButton);
            canvasColorButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    twsbiSelectionMenuDialog.dismiss();
                    pickColour(); // to pick colour
                }
            });

你只要看看你的情况,它会帮助你的。
享受吧。:))

10-07 19:40
查看更多