How to make Smart Custom Alert Dialog in Kotlin – Coding Shiksha

How to make Smart Custom Alert Dialog in Kotlin – Coding Shiksha

Welcome folks to this post. Today in this post we will be talking about a library in kotlin which lets you allow to make Custom Alert Dialog in Kotlin. The screenshot of the Demo Application is given below. Just see and understand it. All the source code is given below.

 

Demo

 

 

 

Download the Library

You can download the library from here

READ  Kotlin(Android) Typing Indicator or Wait Progress Animation - Coding Shiksha

 

How to Include Library?

 

Just add this line to the gradle file of the Application.

implementation 'com.github.TecOrb-Developers:SmartAlertDialog:v1.0'

 

 

Full Source Code Example

 

  1. Layout File

 

activity_main.xml

 

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Open Dialog"
        android:id="@+id/button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

 

READ  Build a About Screen UI in Android Applications with Kotlin - Coding Shiksha

2) Java Code

 

MainActivity.java

 

package com.rahman.smartdialog;

import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.rahman.dialog.Activity.SmartDialog;
import com.rahman.dialog.ListenerCallBack.SmartDialogClickListener;
import com.rahman.dialog.Utilities.SmartDialogBuilder;

public class MainActivity extends AppCompatActivity {

    Context context;
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context=this;

        final Typeface face = Typeface.createFromAsset(context.getAssets(),"ptsanswebbold.ttf");
        final Typeface face2 = Typeface.createFromAsset(context.getAssets(),"ptsanswebregular.ttf");

        button=(Button)findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                new SmartDialogBuilder(context)
                        .setTitle("Smart Dialog")
                        .setSubTitle("This is the alert dialog to showing alert to user")
                        .setCancalable(false)
                        .setTitleFont(face)
                        .setSubTitleFont(face2)
                        .setNegativeButtonHide(false)
                        .setPositiveButton("OK", new SmartDialogClickListener() {
                            @Override
                            public void onClick(SmartDialog smartDialog) {
                                    smartDialog.dismiss();
                            }
                        }).setNegativeButton("Cancel", new SmartDialogClickListener() {
                    @Override
                    public void onClick(SmartDialog smartDialog) {
                        smartDialog.dismiss();

                    }
                }).build().show();
            }
        });


    }
}

 

READ  Kotlin RecyclerView Animation Example - Coding Shiksha

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Leave a Reply

Close Menu

Indian Desi Tools - Ultimate Tools Website

Demo Description


This will close in 20 seconds