Message dialog example
MessageDialog messageDialog = new MessageDialog();
messageDialog.Builder(context)
.setTitle("Title")
.setMessage("Message")
.show();
Apply the default theme to a dialog
messageDialog.Builder(context)
Apply the app theme to a dialog (only works with material3 theme)
messageDialog.Builder(context,true)
Apply the custom theme to a dialog (only works with material3 theme)
messageDialog.Builder(context,theme)
By default dialog colors will be set to material3 dynamic colors. With this method you can set the dialog color for the background and buttons to the older non-dynamic colors
messageDialog.setOldTheme();
With DialogPreset, you can create customized dialogs with consistent customizations. Simply create a DialogPreset and implement it across all dialogs that you want to have that customizations.
DialogPreset<MessageDialog> preset = dialog -> {
// add customization here
};
DialogPreset<MessageDialog> preset = dialog -> {
dialog.setDialogBackgroundResource(background)
.setTextColor(textColor)
.setButtonColor(btnColor);
};
messageDialog.setPresets(preset);
It's recommended to apply the presets first before modifying any other properties
messageDialog.Builder(context,true)
.setPresets(preset)
.setTitle("Title")
.setMessage("Message")
...
messageDialog.onButtonClick(new DialogButtonEvent() {
@Override
public void onButtonClick() {
// Do something
}
});
//or
messageDialog.onButtonClick(() -> {
// Do something
});
messageDialog.onShowListener(dialogInterface -> {
// Do something
});
messageDialog.onDismissListener(dialogInterface -> {
// Do something
});
supported values: INSETS_LEFT
, INSETS_RIGHT
, INSETS_BOTTOM
, INSETS_HORIZONTAL
, INSETS_ALL
or INSETS_NONE
.
messageDialog.applyInsets(INSETS_HORIZONTAL);
You can combine multiple values with bitwise-OR ( | ) operator
messageDialog.applyInsets(INSETS_LEFT | INSETS_RIGHT);
//Create dialog
messageDialog.Builder(context);
//Usin the old dialog theme
messageDialog.setOldTheme();
//Set title
messageDialog.setTitle("Title");
//Set message
messageDialog.setMessage("Message");
//Set title text alignment
messageDialog.setTitleAlignment(TextAlignment);
//Set message text alignment
messageDialog.setMessageAlignment(TextAlignment);
//Set button text
messageDialog.setButtonText("Text");
//Set text color
messageDialog.setTextColor(color);
//Set title text color
messageDialog.setTitleTextColor(color);
//Set message text color
messageDialog.setMessageTextColor(color);
//Set button color
messageDialog.setButtonColor(color);
//Set button text color
messageDialog.setButtonTextColor(color);
//Set button background resource
messageDialog.setButtonBackgroundResource(drawable);
//Set dialog color
messageDialog.setDialogBackgroundColor(color);
//Set dialog background resource
messageDialog.setDialogBackgroundResource(drawable);
//Set maximum dialog width. Default is 600dp
messageDialog.setMaxDialogWidth(width);
//Get maximum dialog width
int dialogWidth = messageDialog.getMaxDialogWidth();
//Get button
Button Button = messageDialog.getButton();
//Set dialog animations
messageDialog.setDialogAnimations(styleRes);
//Enable or disable swipe down to dismiss dialog.
//By default is set to true
dialog.swipeToDismiss(boolean);
//Set dialog onTouchListener.
//This method will overide swipe down to dismiss action
dialog.setOnTouchListener(onTouchListener);
//Apply insets (INSETS_LEFT, INSETS_RIGHT, INSETS_BOTTOM, INSETS_HORIZONTAL, INSETS_ALL or INSETS_NONE)
messageDialog.applyInsets(insets);
//Shew dialog
messageDialog.show();
//Dismiss dialog
messageDialog.dismiss();