Android: Close dialog window on touch

前端 未结 5 1613
时光取名叫无心
时光取名叫无心 2020-12-15 09:25

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

5条回答
  •  囚心锁ツ
    2020-12-15 09:58

    If your dialog contains any view try to get the touch events in that view and dismiss your dialog when user touch on that view. For example if your dialog has any Image then your code should be like this.

    Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.mylayout);
    //create a layout with imageview
    ImageView image = (ImageView) dialog.findViewById(R.id.image);
    image.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v) {
            dialog.dismiss();
        } 
    });
    dialog.show();
    

提交回复
热议问题