How to set dialog's position?

Viewed 13569

I have made a custom dialog.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="myBackgroundStyle"
        parent="@android:style/Theme.Translucent.NoTitleBar" />
</resources>

screenshot

Dialog dialog = new Dialog(this, R.style.myBackgroundStyle);
dialog.setContentView(R.layout.dialog);

dialog.show();

WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.y = 225; params.x = 225;
params.gravity = Gravity.TOP | Gravity.LEFT;       
dialog.getWindow().setAttributes(params); 

But the problem is that it appears in the top left corner and I can't find a way to place it where I need it. params.y=225; params.x=225; somehow don't affect it.

Any ideas?


edit: If I have the xml like that ( style/Theme.Dialog ), then the parameters and location work fine, but a modal shadow appears. Is there a way to remove it?

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="myBackgroundStyle" parent="@android:style/Theme.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">false</item>
    </style>
</resources>
5 Answers
Related