Android Learning

Cool Alert Dialog, Bottomsheet Dialog Android

Hi Friends, Today you will learn how you can add stylish and modern alert dialog to your Android App. You can achieve this using a simple android java library in any android project.

There are 3 types of Alert Dialog you Like:

  • Notification Alert Dialog
  • Simple Alert Dialog
  • Bottom sheet Alert Dialog

How to Add Stylish Alert Dialog to Your Android App:

First of all, Create A New Android Java Project then add the below dependencies to your app-level build.gradle file:

implementation 'com.crowdfire.cfalertdialog:cfalertdialog:1.1.0'

Now sync the project and you are ready to go with cool alert dialog. Wow.

Notification Alert Dialog Android:

This type of alert dialog will show like a Notification Style in your Android App. Check Below Screenshot:

Notification Alert Dialog

Add the below line of code on your button onClick method:

  CFAlertDialog.Builder builder = new CFAlertDialog.Builder(MainActivity.this)
    .setDialogStyle(CFAlertDialog.CFAlertStyle.NOTIFICATION)
    .setTitle("Need Source Code ?")  // Set the title of dialog
    .setMessage("Download All Source Code From NulledSourceCode.com")   // set the message on dialog
    .setIcon(R.drawable.ic_icon)  // set the icon
    // Add a sample positive button
    .addButton("Download Now", -1, -1, CFAlertDialog.CFAlertActionStyle.POSITIVE, CFAlertDialog.CFAlertActionAlignment.JUSTIFIED, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://nulledsourcecode.com"));
        startActivity(intent);
        dialog.dismiss();
      }
    })
    // Add a sample negative button
    .addButton("Grant Permission", -1, -1, CFAlertDialog.CFAlertActionStyle.NEGATIVE, CFAlertDialog.CFAlertActionAlignment.JUSTIFIED, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
         Toast.makeText(MainActivity.this, "Permission Granted", Toast.LENGTH_LONG).show();
        dialog.dismiss();
      }
    });
  // Show the alert
  builder.show();

BottomSheet Alert Dialog:

BottomSheet Alert Dialog

You can easily add this to your android app. Add the below code in your android studio app on button click method:

  CFAlertDialog.Builder builder = new CFAlertDialog.Builder(MainActivity.this)
    .setDialogStyle(CFAlertDialog.CFAlertStyle.BOTTOM_SHEET)
    .setTitle("Need Source Code ?")  // Set the title of dialog
    .setMessage("Download All Source Code From NulledSourceCode.com")   // set the message on dialog
    .setIcon(R.drawable.ic_icon)  // set the icon
    // Add a sample positive button
    .addButton("Download Now", -1, -1, CFAlertDialog.CFAlertActionStyle.POSITIVE, CFAlertDialog.CFAlertActionAlignment.JUSTIFIED, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://nulledsourcecode.com"));
        startActivity(intent);
        dialog.dismiss();
      }
    })
    // Add a sample negative button
    .addButton("Grant Permission", -1, -1, CFAlertDialog.CFAlertActionStyle.NEGATIVE, CFAlertDialog.CFAlertActionAlignment.JUSTIFIED, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
         Toast.makeText(MainActivity.this, "Permission Granted", Toast.LENGTH_LONG).show();
        dialog.dismiss();
      }
    });
  // Show the alert
  builder.show();

Cool Alert Dialog Android:

You can add cool alert dialog like as shown in the below screenshot:

Simple Alert Dialog Android Code

You can achieve this type of stylish android dialog using below lines of code:

  CFAlertDialog.Builder builder = new CFAlertDialog.Builder(MainActivity.this)
    .setDialogStyle(CFAlertDialog.CFAlertStyle.ALERT)
    .setTitle("Need Source Code ?")  // Set the title of dialog
    .setMessage("Download All Source Code From NulledSourceCode.com")   // set the message on dialog
    .setIcon(R.drawable.ic_icon)  // set the icon
    // Add a sample positive button
    .addButton("Download Now", -1, -1, CFAlertDialog.CFAlertActionStyle.POSITIVE, CFAlertDialog.CFAlertActionAlignment.JUSTIFIED, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://nulledsourcecode.com"));
        startActivity(intent);
        dialog.dismiss();
      }
    })
    // Add a sample negative button
    .addButton("Grant Permission", -1, -1, CFAlertDialog.CFAlertActionStyle.NEGATIVE, CFAlertDialog.CFAlertActionAlignment.JUSTIFIED, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
         Toast.makeText(MainActivity.this, "Permission Granted", Toast.LENGTH_LONG).show();
        dialog.dismiss();
      }
    });
  // Show the alert
  builder.show();

The codes for all the 3 types of the alert dialog are simple and the same just you’re to set the position where you want to show the alert dialog. You have to change 2 lines of code which is given below:

.setDialogStyle(CFAlertDialog.CFAlertStyle.ALERT)

Change .ALERT to NOTIFICATION or BOTTOM_SHEET to change its position. Its very simple. If you have any doubts then feel free to comments below

You can download full source code from the below download button

Download

Leave a Comment