Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Dialog is being dismissed when I click outside of it

Tags:

android

dialog

I have a custom dialog that dismisses when you click outside of the dialog, which is what I do not want. Having dialog.setCanceledOnTouchOutside(false); does not fix the problem. What am I doing wrong?

dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(false);
dialog.setContentView(R.layout.twitter_dialog);
// set up edit text and other widgets
dialog.getWindow().setLayout(450, 280);
dialog.show();

EDIT: I am calling this dialog from another dialog that has setCanceledOnTouchOutside(true). Before this dialog is called, the previous dialog is dismissed.

like image 725
heero Avatar asked Nov 28 '22 17:11

heero


2 Answers

This work for me:

dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
like image 36
Race Avatar answered Dec 04 '22 01:12

Race


you can use getDialog().setCanceledOnTouchOutside(false);

like image 195
Rishabh Srivastava Avatar answered Dec 04 '22 01:12

Rishabh Srivastava