Custom Alert Dialog

 1.custom_dialog.xml:


<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:padding="15sp">

    <androidx.cardview.widget.CardView
        android:layout_margin="2dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="10dp">





            <ImageView
                android:layout_marginBottom="5dp"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/alert" />

            <TextView
                android:fontFamily="@font/solaimanlipi"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:padding="5dp"
                android:text="আপনি কি এপ থেকে বের হতে চান??"
                android:textColor="@android:color/black"
                android:textSize="25sp" />

            <LinearLayout
                android:layout_marginTop="5dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="2">

                <Button
                    android:fontFamily="@font/solaimanlipi"
                    android:id="@+id/chancelBTN"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:layout_weight="1"
                    android:background="@drawable/seba_btn"
                    android:text="হ্যা"
                    android:textColor="@color/white"
                    android:textSize="18sp" />

                <Button
                    android:fontFamily="@font/solaimanlipi"
                    android:id="@+id/okBTN"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="5dp"
                    android:layout_weight="1"
                    android:background="@drawable/seba_btn"
                    android:text="না"
                    android:textColor="@color/white"
                    android:textSize="18sp" />

            </LinearLayout>

        </LinearLayout>



    </androidx.cardview.widget.CardView>



</androidx.cardview.widget.CardView>



2 .Java Code :

 //Custom Alert Dialog
    @Override
    public void onBackPressed() {

        ShowDialogBox();

    }

    private void ShowDialogBox (){
        final AlertDialog.Builder alert = new AlertDialog.Builder(this);
        View mView = getLayoutInflater().inflate(R.layout.custom_dialog, null);
        alert.setView(mView);

        final AlertDialog alertDialog = alert.create();
        alertDialog.setCancelable(false);

        mView.findViewById(R.id.chancelBTN).setOnClickListener(v -> {
            alertDialog.dismiss();
            finishAndRemoveTask();
        });

        mView.findViewById(R.id.okBTN).setOnClickListener(v -> {
            alertDialog.dismiss();
        });

        alertDialog.show();
    }

    //Custom Alert Dialog



Comments

Popular posts from this blog

Navigation And Bottom Font Style

Flutter Native Splash