0

I am developing a small app wherein a dialog must popup when the user touches anywhere on the screen and if the dialog is already being displayed then on clicking anywhere outside the dialog box it must disappear. Someone plz give suggestions as to how to go about doing this.

Jeris
  • 2,355
  • 4
  • 26
  • 38

1 Answers1

2

This is possibly duplicate of link

if you want to hide dialog box after touch event then

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

and by overriding the onTouch listener as

public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        dialog.dismiss();
    }
    return false;
}
Community
  • 1
  • 1