Skip to content

05 Specifying the dialog's size and location

Michael Rapp edited this page Dec 27, 2017 · 1 revision

Besides the setter methods, which allow to modify the appearance of a MaterialDialog, the builder MaterialDialog.Builder provides additional methods, which allow to specify the size and location of the dialog. These methods are shown in the following table.

Setter methods Description Default value Restrictions
setFullscreen(boolean):Builder Sets, whether the dialog should be shown fullscreen, or not. false none
setGravity(int):Builder Sets the gravity of the dialog. Dialog.Gravity.CENTER Must be one of the values defined in the interface Dialog.Gravity. Multiple values can be combined by using the bitwise OR operation.
setWidth(int):Builder Sets the width of the dialog in pixels. Dialog.WRAP_CONTENT Must be at least 1, respectively Dialog.WRAP_CONTENT or Dialog.MATCH_PARENT.
setHeight(int):Builder Sets the height of the dialog in pixels. Dialog.WRAP_CONTENT, respectively 580dp on tablets, 480dp on phablets and 528dp on phablets in landscape mode Must be at least 1, respectively Dialog.WRAP_CONTENT or Dialog.MATCH_PARENT.
setMaxWidth(int):Builder Sets the maximum width of the dialog in pixels. -1 Must be at least 1, respectively -1, if no maximum width should be set.
setMaxHeight(int):Builder Sets the maximum height of the dialog in pixels. -1, respectively 800dp on tablets in portrait mode Must be at least 1, respectively -1, if no maximum height should be set.
setMargin(int,int,int,int):Builder Sets the left, top, right and bottom margin of the dialog in pixels. 10dp for all margins All margins must be at least 0.
setFitsSystemWindows(boolean,boolean,boolean,boolean):Builder Sets, whether the dialogs content should be inset at the left, top, right and bottom in order to prevent it from overlapping with the status and navigation bar when using a translucent fullscreen theme. true for all values. When a header is shown, the content is not inset at the top none

The table below shows the theme attributes, which can be used in order to specify the size and location of a dialog as an alternative to the setter methods mentioned above. The attributes must be defined in the theme, which is applied on the dialog.

Theme atttribute Description Format
materialDialogFullscreen Specifies, whether the dialog should be shown fullscreen, or not. boolean
materialDialogWidth Specifies the width of the dialog. dimension
materialDialogHeight Specifies the height of the dialog. dimension
materialDialogMaxWidth Specifies the maximum width of the dialog. dimension
materialDialogMaxHeight Specifies the maximum height of the dialog. dimension
materialDialogMarginLeft Specifies the left margin of the dialog. dimension
materialDialogMarginTop Specifies the top margin of the dialog. dimension
materialDialogMarginTop Specifies the top margin of the dialog. dimension
materialDialogMarginRight Specifies the right margin of the dialog. dimension
materialDialogMarginBottom Specifies the bottom margin of the dialog. dimension
materialDialogGravity Specifies the gravity of the dialog. integer
materialDialogFitsSystemWindowsLeft Specifies, whether the dialog's content should be inset at the left. boolean
materialDialogFitsSystemWindowsTop Specifies, whether the dialog's content should be inset at the top. boolean
materialDialogFitsSystemWindowsRight Specifies, whether the dialog's content should be inset at the right. boolean
materialDialogFitsSystemWindowsBottom Specifies, whether the dialog's content should be inset at the bottom. boolean