How to Cancel an Dialog Themed Like Activity When Touched Outside the Window

Prevent Android activity dialog from closing on outside touch

This could help you. It is a way to handle the touch outside event:

How to cancel an Dialog themed like Activity when touched outside the window?

By catching the event and doing nothing, I think you can prevent the closing. But what is strange though, is that the default behavior of your activity dialog should be not to close itself when you touch outside.

(PS: the code uses WindowManager.LayoutParams)

android 4.0 Dialog gets canceled when touched outside of dialog window

Check this method from the Android Developers site for dialog.

Try using the

dialog.setCanceledOnTouchOutside (boolean cancel)

Pass a boolean value to enable/disable dialog behaviour when touched outside of the dialog window.

Also go through these links:

How do I fire an event when click occurs outside a dialog

How to cancel an Dialog themed like Activity when touched outside the window?

I hope this answers your question.

How to dismiss the dialog with click on outside of the dialog?

You can use dialog.setCanceledOnTouchOutside(true); which will close the dialog if you touch outside of the dialog.

Something like,

  Dialog dialog = new Dialog(context)
dialog.setCanceledOnTouchOutside(true);

Or if your Dialog in non-model then,

1 - Set the flag-FLAG_NOT_TOUCH_MODAL for your dialog's window attribute

Window window = this.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);

2 - Add another flag to windows properties,, FLAG_WATCH_OUTSIDE_TOUCH - this one is for dialog to receive touch event outside its visible region.

3 - Override onTouchEvent() of dialog and check for action type. if the action type is
'MotionEvent.ACTION_OUTSIDE' means, user is interacting outside the dialog region. So in this case, you can dimiss your dialog or decide what you wanted to perform.
view plainprint?

public boolean onTouchEvent(MotionEvent event)  
{

if(event.getAction() == MotionEvent.ACTION_OUTSIDE){
System.out.println("TOuch outside the dialog ******************** ");
this.dismiss();
}
return false;
}

For more info look at How to dismiss a custom dialog based on touch points? and
How to dismiss your non-modal dialog, when touched outside dialog region

how to set cancellable false to an activity when it is opened as a Dialog?

You can do that in Java coding very easily.
If you have an Activity (even if it looks like a Dialog), then you should do

this.setFinishOnTouchOutside(false);

if you have used Dialog class, you should call

dialog.setFinishOnTouchOutside(false) 

if you want to prevent closing it open when the background activity is clicked.

How do I fire an event when click occurs outside a dialog

It Works For me,,

        Window window = dialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

dialog.show();

See this http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_NOT_TOUCH_MODAL

Activity with Theme.Dialog can be dismissed when user touches anywhere on screen, but not with Theme.panel

Have you tried this.setFinishOnTouchOutside(false); ?

This being your activity.



Related Topics



Leave a reply



Submit