Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove dialog margins?

Tags:

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... enter image description here

I have this... enter image description here

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);

like image 690
Felipe Porge Xavier Avatar asked Jul 04 '15 13:07

Felipe Porge Xavier


People also ask

How do I turn off custom dialog?

You may call dismiss(); on the dialog.

How do you give a dialog margin?

x yourDialog. getWindow(). setAttributes(params); Just add this before your show your dialog.


1 Answers

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.

like image 162
Damian Kozlak Avatar answered Oct 14 '22 03:10

Damian Kozlak