Currently, I have the following dialog, which I will perform expand/ collapse animation on its items.

[![enter image description here](https://i.stack.imgur.com/2iArF.png)](https://i.stack.imgur.com/2iArF.png)

This dialog is created via the following code

```
import android.support.v7.app.AlertDialog;

final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final AlertDialog dialog = builder.setView(view).create();
final ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

    public void onGlobalLayout() {
        ViewTreeObserver obs = view.getViewTreeObserver();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
            obs.removeOnGlobalLayoutListener(this);
        } else {
            obs.removeGlobalOnLayoutListener(this);
        }

        // http://stackoverflow.com/questions/19326142/why-listview-expand-collapse-animation-appears-much-slower-in-dialogfragment-tha
        int width = dialog.getWindow().getDecorView().getWidth();
        int height = dialog.getWindow().getDecorView().getHeight();
        dialog.getWindow().setLayout(width, height);
    }
});

```

However, when animation being performed, here's the side effect.

[![enter image description here](https://i.stack.imgur.com/jVJ0v.png)](https://i.stack.imgur.com/jVJ0v.png)

Note, the unwanted extra white region at the dialog after animation, is not caused by our custom view. It is the system window white background of the dialog itself.

I tend to make the system window background of the dialog, to become transparent.

```
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final AlertDialog dialog = builder.setView(view).create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

```

**Although the unwanted white background is no longer seen, the original margin of the dialog is gone too. (The dialog width is now full screen width)**

[![enter image description here](https://i.stack.imgur.com/pyFia.png)](https://i.stack.imgur.com/pyFia.png)

*How can I make it transparent, without affecting its margin?*