Button button = findViewById(R.id.dismiss_button); final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_layout); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show();
final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_layout); dialog.show(); new Handler().postDelayed(new Runnable() { @Override public void run() { dialog.dismiss(); } }, 5000); //dismiss dialog after 5 secondsThis example creates a Dialog object and shows it immediately. A Handler object is then used to post a delayed action that dismisses the dialog after a specified time interval. Package library: android.os