Does anybody knows how can I set margins to a custom dialog? I\'m asking because I\'ve a custom dialog but when displayed it stretches to fill the parent, even though I set
If you are creating a custom dialog with the background you can prefer the following code.
You can change window property MATCH_PARENT
for full screen.
My issue was width of dialog matching to its parent without margin
try following code as per requirement
Window window = event_dialog.getWindow();
window.setGravity(Gravity.CENTER);
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.width = WindowManager.LayoutParams.MATCH_PARENT;
wlp.height = WindowManager.LayoutParams.WRAP_CONTENT;
wlp.flags &= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
set these property before dialog.show()
OR you can set LEFT,RIGHT,TOP,BOTTOM
margin to your dialog by setting margin
to your root
layout and custom background
to its child layout like