The following code will create a simple one-button dialog box. The following code setTitle()uses the method to set the Title to alert dialog. setMessage()used to set the message dialog box. setIcon()- set the icon in the notification dialog box
AlertDialog alertDialog = new AlertDialog.Builder(
AlertDialogActivity.this).create();
alertDialog.setTitle("Alert Dialog");
alertDialog.setMessage("Welcome to AndroidHive.info");
alertDialog.setIcon(R.drawable.tick);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
}
});
alertDialog.show();
source
share