Skip to content
Marsad Maqsood edited this page Jan 24, 2022 · 10 revisions

Table of Contents

  1. Dialog Type
  2. Title Text
  3. Content Text
  4. Cancelled On Touch Outside
  5. Dialog Cancellation
  6. Custom View
  7. Listeners
  8. Buttons
  9. Customization
  10. Dialog Gravity
  • Dialog Type
StylishAlertDialog.NORMAL
StylishAlertDialog.ERROR
StylishAlertDialog.SUCCESS
StylishAlertDialog.WARNING
StylishAlertDialog.PROGRESS
StylishAlertDialog.CUSTOM_IMAGE

StylishAlertDialog(Context context, StylishAlertDialog stylishAlertDialog);

//Initialize dialog
StylishAlertDialog dialog = new StylishAlertDialog(this, StylishAlertDialog.NORMAL);
  • Title Text
dialog.setTitleText(String text)
  • Content Text
dialog.setContentText(String text)
  • Prevent dialog from dismissing when clicked outside the dialog
dialog.setCancelledOnTouchOutside(false)
  • Prevent dialog from cancelling
dialog.setCancellable(false)
  • Set custom view
dialog.setCustomView(View view, boolean withContent)
//set withContent to true if you want to show content text with custom view

//For example
View view = LayoutInflater.from(this).inflate(R.layout.custom_view,null, false);
dialog.setCustomView(view, true);
//dialog.setCustomView(editText, true);
  • More convenient interface to bind listeners (like in AlertDialog)
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
    @Override
    public void onShow(DialogInterface dialog) {
    
    }
});

dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialogInterface) {
            //dialog dismissed
            //dialog dismissed with animation

        }
});
    
dialog.setCancelClickListener(new StylishAlertDialog.OnStylishClickListener() {
        @Override
        public void onClick(StylishAlertDialog stylishDialog) {
            //dialog canceled
            
        }
});
    
dialog.setConfirmClickListener(new StylishAlertDialog.OnStylishClickListener() {
        @Override
        public void onClick(StylishAlertDialog stylishDialog) {
        
        }
});

dialog.setCancelButton("Cancel", new StylishAlertDialog.OnStylishClickListener() {
        @Override
        public void onClick(StylishAlertDialog stylishDialog) {

        }
});
    
dialog.setConfirmButton("Confirm", new StylishAlertDialog.OnStylishClickListener() {
        @Override
        public void onClick(StylishAlertDialog stylishDialog) {

        }
});

dialog.setNeutralButton("Neutral", new StylishAlertDialog.OnStylishClickListener() {
        @Override
        public void onClick(StylishAlertDialog stylishDialog) {

        }
});
    
  • Third neutral button with own listener, colors, methods and etc
  • Disable buttons
dialog.getButton(StylishAlertDialog.BUTTON_CONFIRM).setEnabled(false); 
dialog.getButton(StylishAlertDialog.BUTTON_CANCEL).setEnabled(false);
  • Hide buttons after changing the alert type
dialog.getButton(StylishAlertDialog.BUTTON_CONFIRM).setVisibility(View.GONE);
dialog.getButton(StylishAlertDialog.BUTTON_CANCEL).setVisibility(View.GONE);
  • Set the buttons stroke width
dialog.setStrokeWidth(12f);
  • Dark style of dialogs
  • Ability to make dialogs without buttons
  • Support of HTML tags
  • Set text size
dialog.setContentTextSize(int value);
  • Change button color
dialog.getButton(StylishAlertDialog.BUTTON_CONFIRM).setBackgroundTintList(ColorStateList.valueOf(Color.GREEN));

dialog.getButton(StylishAlertDialog.BUTTON_CANCEL).setBackgroundTintList(ColorStateList.valueOf(Color.YELLOW));
  • Set background color of buttons
dialog.setConfirmButtonBackgroundColor(Integer color);
dialog.setCancelButtonBackgroundColor(Integer color);
dialog.setNeutralButtonBackgroundColor(Integer color);
  • Set button text color
dialog.setConfirmButtonTextColor(Integer color);
dialog.setCancelButtonTextColor(Integer color);
dialog.setNeutralButtonTextColor(Integer color);
  • Set Dialog Gravity
dialog.getWindow().setGravity(Gravity.CENTER);
Clone this wiki locally