DialogFragment setCancelable property not working

后端 未结 5 2071
闹比i
闹比i 2020-12-25 09:25

I am working in an android application and am using a DialogFragment to show a dialog and I want to make that DialogFragment not cancelable. I have made the dialog cancelabl

5条回答
  •  不思量自难忘°
    2020-12-25 09:45

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
        View view = inflater.inflate(R.layout.dialog_test, container, true);
        getDialog().requestWindowFeature(STYLE_NO_TITLE);
        getDialog().setCancelable(false);
    
        return view;
    }
    

    instead of getDialog().setCancelable(false); you have to use directly setCancelable(false);

    so the updated answer will be like this

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
        View view = inflater.inflate(R.layout.dialog_test, container, true);
        getDialog().requestWindowFeature(STYLE_NO_TITLE);
        setCancelable(false);
    
        return view;
    }
    

提交回复
热议问题