I have made a custom dialog.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="myBackgroundStyle"
parent="@android:style/Theme.Translucent.NoTitleBar" />
</resources>
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>
You can Use Align widget and align your dialog widget as per your need. Here in example i am setting it to the bottomCenter that is Alignment(0, 1) . Example code: Align( alignment: Alignment(0, 1), child: Material( shape: RoundedRectangleBorder(borderRadius: BorderRadius.
requestWindowFeature(Window. FEATURE_NO_TITLE); dialog. getWindow(). setBackgroundDrawable(new ColorDrawable(0)); LayoutInflater inflator = (LayoutInflater) getApplicationContext() .
setMessage() is used for setting message to alert dialog. setIcon() is to set icon to alert dialog. The following code will create alert dialog with two button. setPositiveButton() is used to create a positive button in alert dialog and setNegativeButton() is used to invoke negative button to alert dialog.
Try creating a new set of parameters:
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.y = 225; params.x = 225;
params.gravity = Gravity.TOP | Gravity.LEFT;
dialog.getWindow().setAttributes(params);
Edit: if you want to preserve the window's attributes, you could try adding this as the second line:
params.copyFrom(dialog.getWindow().getAttributes());
However, note that the copyFrom
method is completely undocumented, so I have no idea if it does what it sounds like it does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With