Prevent back button from closing a dialog box

前端 未结 7 1319
别那么骄傲
别那么骄傲 2021-01-30 05:17

I am trying to prevent an AlertDialog box from closing when pressing the back button in Android. I have followed both of the popular methods in this thread, and with System.out.

7条回答
  •  梦如初夏
    2021-01-30 05:31

    Use setCancelable(false)

    SampleDialog sampleDialog = SampleDialog.newInstance();
    sampleDialog.setCancelable(false);
    sampleDialog.show(getSupportFragmentManager(), SampleDialog.class.getSimpleName());
    

提交回复
热议问题