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) {

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;

public Dialog onCreateDialog(Bundle bundle) {
    bundle = super.onCreateDialog(bundle);
    return bundle;

public void onDestroyView() {


2 Answers

Arbaz Pirwani On Best Solutions

You can set cancel able false in your onCreateDialog method

like this

Hasan Kucuk On

If you define rootLayout, you can disable all views in the layout.You can also apply activity before opening the dialogfragment.

public static void enableDisableView(View view, boolean enabled) {
        if ( view instanceof ViewGroup) {
            ViewGroup group = (ViewGroup)view;

            for ( int idx = 0 ; idx < group.getChildCount() ; idx++ ) {
                enableDisableView(group.getChildAt(idx), enabled);