1

In my application I'm displaying an image inside a dialog. If the user presses the button the dialog appears and takes 80% of the whole screen. The background will be dimmed because that is the default behavior of the Android Dialog.

Dialog dialog = new Dialog(ActQuiz.this);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
                dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        //nothing;
                    }
                });

                int width = (int) (getResources().getDisplayMetrics().widthPixels * 0.80);
                int height = (int) (getResources().getDisplayMetrics().heightPixels * 0.80);
                dialog.getWindow().setLayout(width, height);
                ImageView imageView = new ImageView(ActQuiz.this);
                String uri = "@drawable/" + info.getInfopicture();
                int imageResource = getResources().getIdentifier(uri, null, getPackageName());
                Drawable myDrawable = ContextCompat.getDrawable(ActQuiz.this, imageResource);
                imageView.setImageDrawable(myDrawable);
                new PhotoViewAttacher(imageView);
                dialog.addContentView(imageView, new RelativeLayout.LayoutParams(width, height));
                dialog.show();

So what I want to achieve is to disable the dimming for a Button, which is visible behind the dialog.

enter image description here

Is this possible or can I only remove the dimming for the whole background?

azizbekian
  • 60,783
  • 13
  • 169
  • 249
Deno Agüero
  • 519
  • 2
  • 9
  • 27
  • you can clear the Dim background behind the Dialog...is that ok ? – rafsanahmad007 Jul 15 '17 at 12:57
  • You probably mean: clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHI‌​ND). But it will remove the dimming for the whole background. I only want it for the button. You can see it in my post. – Deno Agüero Jul 15 '17 at 13:03
  • you can check this out: https://stackoverflow.com/questions/14030154/how-to-dim-blur-only-part-of-the-screen – rafsanahmad007 Jul 15 '17 at 13:23

1 Answers1

1

Is this possible or can I only remove the dimming for the whole background?

It's not possible to instruct Dialog to dim everything except some view, or some region. There is no such an API to do that.

What you can do, is to provide your custom drawable as a background to Dialog's window. That drawable would be given a Rect with coordinates of Button and a Rect of the screen. It will draw a dim (basically a semitransparent black color) everywhere except the provided rectangle. Looks like xfermode SrcOut is the mode that should be applied.

azizbekian
  • 60,783
  • 13
  • 169
  • 249