Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Close dialog window on touch

I'd like to close a dialog window in my android app by simply touching the screen.. is this possible? If so, how?

I've looked into setting some "onClickEven" on the dialog, but it doesnt exist.

How would this be possible?

like image 434
Linora Avatar asked Apr 27 '11 09:04

Linora


People also ask

How do you dismiss dialog with click on outside of dialog?

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

What is dialogue box in android?

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed. Dialog Design.


2 Answers

Dialog dialog = new Dialog(context)
{
    public boolean dispatchTouchEvent(MotionEvent event)  
    {
        dialog.dismiss();
        return false;
    }
};

And you are done!

like image 61
Yuwen Avatar answered Oct 23 '22 12:10

Yuwen


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

like image 41
Jaibabu Avatar answered Oct 23 '22 11:10

Jaibabu