user7722687
user7722687

Reputation:

How to dismiss dialog when I click any where in dialog in android

 final Dialog dialog = new Dialog(context);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setContentView(R.layout.dialog_image);
            ImageView dialogIv = (ImageView)dialog.findViewById(R.id.dialog_iv);
            TextView dialogTV = (TextView)dialog.findViewById(R.id.dialog_med_name);
            dialog.show();

When i click on anywhere on dialog it should dismiss.Full Screen its imageview dialog.

Upvotes: 0

Views: 122

Answers (3)

Abhishek Kumar
Abhishek Kumar

Reputation: 1265

One thing you can do,Just set clicklistner on your Imageview.

 dialogIv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                }
            });

Upvotes: 1

Rachit
Rachit

Reputation: 3235

You can create your own Touch Listener, and dismiss the dialog on the UP event.

class MyTouchListener implement OnTouchListener{
public boolean onTouch(View v, MotionEvent event)
{
    if(event.getAction() == MotionEvent.ACTION_UP){
        // DISMISS DIALOG      
    }
    return true;
}

And then set this listener to your dialog

MyTouchListener l = new MyTouchListener();
dialog.setOnTouchListener(l);

Upvotes: 0

albeee
albeee

Reputation: 1472

setCanceledOnTouchOutside

Added in API level 1

void setCanceledOnTouchOutside (boolean cancel)

Sets whether this dialog is canceled when touched outside the window's bounds. If setting to true, the dialog is set to be cancelable if not already set.

Parameterscancelboolean: Whether the dialog should be canceled when touched outside the window.

Upvotes: 0

Related Questions