Header Ads

Header ADS

Customized Alert Dialog android

 Xml :


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical">
>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="300dp"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="3">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:background="@android:color/darker_gray"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:text="Hello"
android:textColor="@android:color/white"
android:textStyle="bold" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Provie Email Please Check your Email" />


</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center">

<Button
android:id="@+id/procedBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/holo_orange_light"
android:text="Proces" />
</LinearLayout>

</LinearLayout>

</androidx.cardview.widget.CardView>

</LinearLayout>

Java:
package com.rztechtunes.myapplication;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

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


}

public void Button(View view) {
AlertDialog.Builder build = new AlertDialog.Builder(this);
LayoutInflater mlLayoutInflater=LayoutInflater.from(MainActivity.this);
final View dialView=mlLayoutInflater.inflate(R.layout.allert_layout,null);
build.setView(dialView);
Button proced = dialView.findViewById(R.id.procedBtn);

proced.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Button Clicked", Toast.LENGTH_SHORT).show();
}
});
AlertDialog dialog_card = build.create();
dialog_card.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog_card.show();

}


}


No comments

Theme images by Matt Vince. Powered by Blogger.