0

I have an AlertDialog.Builder but the problem is that when the AlertDialog.Builder is showing I am unable to click on the toolbar becase AlertDialog.Builder is drawn above all other views.. how do I make this AlertDialog.Builder not cancel able but still be able to click on toolbar items.

here is a snapshot for a better understandingI want to be able to click on cart icon, wishist icon and navigation drawer when the AlertDialog.Builder is showing.

HERE IS MY CODE:

final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                                //Set title

                                builder.setTitle("Approval Pending")
                                        //Set message
                                        .setMessage("Your account with Reference Id [" + jObj0.getString("reference_id") + "] is in Pending state.")
                                        .setNegativeButton("REFRESH", new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int which) {
                                                if(Utils.isConnected(getContext())) {
                                                    dialog.dismiss();
                                                    fetchdashboardfragmentdata(true);
                                                }else{
                                                    builder.show();
                                                    Toast.makeText(getContext(), "Please turn on your Internet connection and try again", Toast.LENGTH_SHORT).show();
                                                }
                                            }
                                        })
                                        .setPositiveButton("LOGOUT", new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int which) {
                                                StoreSharePreference.SSP().logout(getContext());
                                                Intent intent = new Intent(getContext(), Login_Page.class);
                                                intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_CLEAR_TASK);
                                                startActivity(intent);
                                                getActivity().finish();
                                            }
                                        })
                                        .setOnKeyListener(new DialogInterface.OnKeyListener() {
                                            @Override
                                            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                                                if (keyCode == KeyEvent.KEYCODE_BACK) {
                                                    Intent intent = new Intent(Intent.ACTION_MAIN);
                                                    intent.addCategory(Intent.CATEGORY_HOME);
                                                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                                    startActivity(intent);
                                                    return true;
                                                }
                                                return false;
                                            }
                                        })
                                        .setCancelable(false);
                                AlertDialog alert = builder.create();
alert.show();

--I want to be able to click on cart icon, wishist icon and navigation drawer when the AlertDialog.Builder is showing.--

Shahid Sarwar
  • 1,209
  • 14
  • 29

2 Answers2

0

you can't touch element behind an alert dialog, because dialog always overlaying your activity. you have to dismiss the dialog before touching the activity UI components.

Ashish
  • 132
  • 3
  • 9
0

you can do this by using

AlertDialog helpDialog = alert.create();

Window window = helpDialog.getWindow();

window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,

WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);

window.setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                        WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
NewCEO
  • 51
  • 1
  • 7