I'm trying to create a custom dialog to show a list of values at the bottom of screen.
How can I remove the dialog margins?
I want this...
I have this...
Dialog code:
Dialog d = new Dialog(this); d.requestWindowFeature(Window.FEATURE_NO_TITLE); d.setContentView(R.layout.dialog_options); Window window = d.getWindow(); WindowManager.LayoutParams wlp = window.getAttributes(); wlp.width = WindowManager.LayoutParams.MATCH_PARENT; wlp.gravity = Gravity.BOTTOM; window.setAttributes(wlp); d.show();
Solved! Better solution:
<style name="BottomOptionsDialogTheme" parent="Theme.AppCompat.Light.Dialog"> <item name="android:windowBackground">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">false</item> <item name="android:layout_margin">0dp</item> <item name="android:padding">0dp</item> <item name="android:layout_gravity">bottom</item> <item name="colorPrimary">@color/orange_dark</item> <item name="colorPrimaryDark">@color/orange_dark</item> <item name="colorAccent">@color/gray_light</item> </style>
And use new Dialog(context, R.theme.BottomOptionsDialogTheme);
You may call dismiss(); on the dialog.
x yourDialog. getWindow(). setAttributes(params); Just add this before your show your dialog.
Change your line:
Dialog d = new Dialog(this);
to:
Dialog d = new Dialog(this, R.style.DialogTheme);
and add in your styles.xml
with parent
corresponding to your theme version.
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog"> <!-- Customize your theme here. --> <item name="android:windowBackground">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">false</item> </style>
But in your situation it can be better to use Snackbar
in my opinion. Here is tutorial.
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