项目作者: yeyintkoko1788

项目描述 :
Custom Alert Dialog
高级语言: Java
项目地址: git://github.com/yeyintkoko1788/AlertDialog.git
创建时间: 2019-06-26T09:16:46Z
项目社区:https://github.com/yeyintkoko1788/AlertDialog

开源协议:Apache License 2.0

下载


AlertDialog

API

Custom Alert Dialog with styles

AlertDialog with custom style

Prerequisites

Add this to your module’s build.gradle file

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }

Dependency

Add this to your module’s build.gradle file

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

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.

  1. CustomAlertDialog dialog = new CustomAlertDialog(this, style);

For style parameter you can choose:

  1. CustomAlertDialog.DialogStyle.DEFAULT
  2. CustomAlertDialog.DialogStyle.NO_ACTION_BAR
  3. CustomAlertDialog.DialogStyle.CURVE
  4. 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
    1. dialog.setAlertTitle("Alert Title");
    2. dialog.setAlertMessage("Alert message...");
  • For Positive and Negative button use following method with onClickListener
    1. dialog.setPositiveButton("Ok", new View.OnClickListener() {
    2. @Override
    3. public void onClick(View v) {
    4. Toast.makeText(getApplicationContext(),"Positive Button Clicked",Toast.LENGTH_SHORT).show();
    5. dialog.dismiss();
    6. }
    7. });
    8. dialog.setNegativeButton("Cancel", new View.OnClickListener() {
    9. @Override
    10. public void onClick(View v) {
    11. Toast.makeText(getApplicationContext(),"Negative Button Clicked",Toast.LENGTH_SHORT).show();
    12. dialog.cancel();
    13. }
    14. });
  • You can also set Alert Dialog type for all style, Such as
    1. dialog.setDialogType(CustomAlertDialog.DialogType.ERROR);
    Currently available type are:
    1. CustomAlertDialog.DialogType.DEFAULT
    2. CustomAlertDialog.DialogType.ERROR
    3. CustomAlertDialog.DialogType.SUCCESS
    4. CustomAlertDialog.DialogType.INFO
    5. 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

    1. dialog.setDialogImage(getDrawable(R.drawable.alert),0); // no tint
    2. 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
    1. dialog.setImageSize(150,150);

  • Finally you can create and show your alert Don’t forget to add this two

    1. dialog.create();
    2. dialog.show();

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