Search code examples
androiddialogfragment

Turn off click activity behind DialogFragment?


I can't cancel the click event of the buttons in the background when I open a dialog fragment. I'm trying to call the dialog fragment via a button in another fragment.

public class DialogPaymentSuccessFragment extends DialogFragment {
private View root_view;
class rootViewClick implements OnClickListener {
    rootViewClick () {
    }

    public void onClick(View view) {
        DialogPaymentSuccessFragment.this.dismiss();
    }
}

public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
    this.root_view = layoutInflater.inflate(R.layout.dialog_payment_success, viewGroup, false);
    ((FloatingActionButton) this.root_view.findViewById(R.id.fab)).setOnClickListener(new rootViewClick());
    return this.root_view;
}

@NonNull
public Dialog onCreateDialog(Bundle bundle) {
    bundle = super.onCreateDialog(bundle);
    bundle.requestWindowFeature(1);
    return bundle;
}

public void onDestroyView() {
    super.onDestroyView();
}

}


Solution

  • You can set cancel able false in your onCreateDialog method

    like this

    this.setCancelable(false)