1Rect displayRectangle = new Rect();
2Window window = MainActivity.this.getWindow();
3window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);
4final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this,R.style.CustomAlertDialog);
5ViewGroup viewGroup = findViewById(android.R.id.content);
6View dialogView = LayoutInflater.from(v.getContext()).inflate(R.layout.customview, viewGroup, false);
7dialogView.setMinimumWidth((int)(displayRectangle.width() * 1f));
8dialogView.setMinimumHeight((int)(displayRectangle.height() * 1f));
9builder.setView(dialogView);
10final AlertDialog alertDialog = builder.create();
11Button buttonOk=dialogView.findViewById(R.id.buttonOk);
12buttonOk.setOnClickListener(new View.OnClickListener() {
13 @Override
14 public void onClick(View v) {
15 alertDialog.dismiss();
16 }
17});
18alertDialog.show();