MainActivity.Java CODE: Select All package demo.alertdialog;import android.content.DialogInterface;import android.support.v7.app.AlertDialog;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button btnShow = (Button)findViewById(R.id.btnAlertDialog); btnShow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("Xác nhận"); //Thiết lập tiêu đề cho Dialog alertDialog.setMessage("Bạn có muốn thoát ?"); //Thiết lập nội dung cho Dialog alertDialog.setIcon(R.mipmap.ic_launcher); //Thiết lập icon cho Dialog alertDialog.setPositiveButton("Có", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finishAffinity(); //Sự kiện khi click vào "Có" thì ứng dụng sẽ đóng lại } }); alertDialog.setNegativeButton("Không", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); //Sự kiện khi click vào "Không" thì hộp thoại Alert Diaglog sẽ đóng lại } }); alertDialog.create().show(); } }); }} File: ty_main.xml CODE: Select All <?xml version="1.0" encoding="utf-8"?><RelativeLayout 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="cnttqn.tranvancuong.k7.kt.MainActivity"> <EditText android:id="@+id/nhapa" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignStart="@+id/nhapb" android:ems="10" android:inputType="textPersonName" /> <EditText android:id="@+id/nhapb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_below="@+id/nhapa" android:layout_marginEnd="27dp" android:layout_marginTop="15dp" android:ems="10" android:inputType="textPersonName" /> <Button android:id="@+id/giaipt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:text="Giải PT" android:layout_below="@+id/nhapc" android:layout_alignStart="@+id/nhapc" /> <Button android:id="@+id/tieptuc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/giaipt" android:layout_alignBottom="@+id/giaipt" android:layout_marginEnd="19dp" android:layout_toStartOf="@+id/nhapa" android:text="Tiếp tục" /> <Button android:id="@+id/thoat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/giaipt" android:layout_marginStart="15dp" android:layout_toEndOf="@+id/giaipt" android:text="Thoát" /> <EditText android:id="@+id/nhapc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignStart="@+id/nhapb" android:layout_below="@+id/nhapb" android:ems="10" android:inputType="textPersonName" /> <EditText android:id="@+id/ht" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignStart="@+id/tieptuc" android:layout_centerVertical="true" android:ems="10" android:inputType="textPersonName" android:text="Hien thi" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/nhapb" android:layout_alignStart="@+id/tieptuc" android:layout_marginBottom="10dp" android:text="Nhập A" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignStart="@+id/textView2" android:layout_alignTop="@+id/nhapb" android:text="Nhập B" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignStart="@+id/textView3" android:layout_below="@+id/nhapb" android:text="Nhập C" /> <EditText android:id="@+id/editText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/ht" android:layout_centerHorizontal="true" android:layout_marginTop="57dp" android:ems="10" android:inputType="textPersonName" android:text="Name" /></RelativeLayout>