0

I've spent a large amount of time trying to solve this issue both by myself and searching through here to find a solution, none of which have worked for me.

My current scenario is when a popup window appears I want to disable all clickable events on the foreground view which is underneath the popup window.

if (Shared.InspectionData.JobViewModel.RAMS_Id == null || Shared.InspectionData.JobViewModel.RAMS_Id.equals("")) {
        // Disable foreground view here

        LoadRAMSPopup();
}



private void LoadRAMSPopup() {
    mainLayout.getForeground().setAlpha(150);
    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);

    final View ramsView = layoutInflater.inflate(R.layout.popup_rams, null);
    final PopupWindow popupRAMS = new PopupWindow(
            ramsView,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
    );

    if (Build.VERSION.SDK_INT >= 21) {
        popupRAMS.setElevation(5.0f);
    }

    findViewById(R.id.mainLayout).post(new Runnable() {
        @Override
        public void run() {
            popupRAMS.showAtLocation(findViewById(R.id.mainLayout), Gravity.CENTER, 0, 0);
            popupRAMS.setOutsideTouchable(false);
            popupRAMS.update();

            Button btnGenerate = (Button) ramsView.findViewById(R.id.btnGenerate);
            btnGenerate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    Intent intent = new Intent(getApplicationContext(), CreateRAMSActivity.class);
                    startActivity(intent);
                    popupRAMS.dismiss();
                    mainLayout.getForeground().setAlpha(0);
                }
            });
        }
    });
}
jmckie
  • 241
  • 4
  • 11

1 Answers1

0

Hitchhiking off of Akshay Mukadam Disabling all child views inside the layout. I've tweaked it slightly to include enabling my views.

public static void disableEnableViews(ViewGroup layout) {
    layout.setEnabled(false);
    for (int i = 0; i < layout.getChildCount(); i++) {
        View child = layout.getChildAt(i);
        if (child instanceof ViewGroup) {
            disableEnableViews((ViewGroup) child);
        } else {
            if(child.isEnabled()){
                child.setEnabled(false);
            } else {
                child.setEnabled(true);
            }
        }
    }
}

Simply give your top view an id, reference it, and then put into the method.

Community
  • 1
  • 1
Avenious
  • 78
  • 8