Reputation: 2256
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);
Upvotes: 23
Views: 16433
Reputation: 7083
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.
Upvotes: 35