Skip to content

yeyintkoko1788/AlertDialog

Repository files navigation

AlertDialog

API

Custom Alert Dialog with styles

AlertDialog with custom style

Prerequisites

Add this to your module's build.gradle file

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Dependency

Add this to your module's build.gradle file

dependencies {
	        implementation 'com.github.yeyintkoko1788:AlertDialog:v1.0.0'
	}

How To Use

In your activity or fragment setup CustomAlertDialog This method always returns a AlertDialog object, so you can customize the Alert much more.

CustomAlertDialog dialog = new CustomAlertDialog(this, style);

For style parameter you can choose:

CustomAlertDialog.DialogStyle.DEFAULT
CustomAlertDialog.DialogStyle.NO_ACTION_BAR
CustomAlertDialog.DialogStyle.CURVE
CustomAlertDialog.DialogStyle.FILL_STYLE

More Style will come soon

DEFAULT

NO_ACTION_BAR

CURVE

FILL_STYLE

  • Use this methods to set Alert Title (except for FILL_STYLE alert) and Alert Message
  • dialog.setAlertTitle("Alert Title");
    dialog.setAlertMessage("Alert message...");
    
  • For Positive and Negative button use following method with onClickListener
  • dialog.setPositiveButton("Ok", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getApplicationContext(),"Positive Button Clicked",Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                }
            });
            dialog.setNegativeButton("Cancel", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getApplicationContext(),"Negative Button Clicked",Toast.LENGTH_SHORT).show();
                    dialog.cancel();
                }
            });
    
  • You can also set Alert Dialog type for all style, Such as
  • dialog.setDialogType(CustomAlertDialog.DialogType.ERROR);
    
    Currently available type are:
    CustomAlertDialog.DialogType.DEFAULT
    CustomAlertDialog.DialogType.ERROR
    CustomAlertDialog.DialogType.SUCCESS
    CustomAlertDialog.DialogType.INFO
    CustomAlertDialog.DialogType.WARNING
    
  • For NO_ACTION_BAR and FILL_STYLE alert style you can set your own image drawable along with image tint color if you don't want image tint you can simply set this attribute to 0
    dialog.setDialogImage(getDrawable(R.drawable.alert),0); // no tint
    dialog.setDialogImage(getDrawable(R.drawable.alert),getResources().getColor(R.color.colorWhite)); //with tint
    
  • You can also define size of image you set by using this method
  • dialog.setImageSize(150,150);
    
  • Finally you can create and show your alert Don't forget to add this two
    dialog.create();
    dialog.show();
    

    This is my first library, so hope you guys enjoy its and feel free to give any suggesting.