如何在 android studio 中创建自动弹出窗口 window

How to create auto popup window in android studio

我想在应用程序的第一页创建一个自动弹出窗口 window。但我似乎无法在网上找到任何教程。有谁请指导。任何帮助将不胜感激。

谢谢。

public void openDialog(View view){
  AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
  alertDialogBuilder.setMessage("Are you sure,You wanted to make decision");

  alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface arg0, int arg1) {
        Toast.makeText(MainActivity.this,"You clicked yes button",Toast.LENGTH_LONG).show();
     }
  });

  alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which) {
        finish();
     }
  });

  AlertDialog alertDialog = alertDialogBuilder.create();
  alertDialog.show();

}

只要调用这个方法openDialog();在你的 setContentView(R.layout.activity_main); 之后 例子

setContentView(R.layout.activity_main);
openDialog();