Dialog dialog box
A dialog box is a small window that prompts the user to make a decision or enter other information.
In general, we use Alert Dialog the longest, but seldom use Dialog directly.
The Dialog class is the base class for dialogs, but you should avoid instantiating Dialog directly. Instead, use one of the following subclasses:
Official documents say instances should be avoided Dialog Direct. Instead, use one of the following subclasses
AlertDialog, DatePickerDialog,TimePickerDialog,ProgressDialog.
Note: ProgressDialog is not recommended as it prevents users from interacting with applications while displaying progress
Now let's talk about Alert Dialog.
Play a common app update cartridge
Note that because of version problems, the font position of the bullet-box may be different. If you see that it is different from other people's settings of the bullet-box, the version may be used differently.
Alert Dialog has a common way of creating and writing, just as chain writing does in the following two code implementations
AlertDialog.Builder dialog = new AlertDialog.Builder(InflateActivity.this); dialog.setIcon(R.mipmap.ic_launcher); dialog.setTitle("Reminder"); dialog.setMessage("Discover the new version, is it updated?"); dialog.setPositiveButton("To update", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialog.show();
And Chain Writing
AlertDialog.Builder builder = new AlertDialog.Builder(InflateActivity.this) .setIcon(R.mipmap.ic_launcher).setTitle("Reminder").setMessage("hair //New version, is it an update? .setPositiveButton("To update", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.show();
How Dialog Sets Unclickable Areas Beyond Bombs
dialog.setCancelable(false);
Bombs of three buttons
The code is as follows
AlertDialog.Builder dialog = new AlertDialog.Builder(InflateActivity.this); dialog.setIcon(R.mipmap.ic_launcher); dialog.setTitle("Reminder"); dialog.setMessage("Discover the new version, is it updated?"); dialog.setPositiveButton("To update", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setNeutralButton("ignore", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setCancelable(false); dialog.show();
You can see if you want the text to be on the left.
Use
setNeutralButton
If you use it on the far right
setPositiveButton
There is currently no middle ground for the system version, even using setNegative Button on the far right.
Dialog of the list
The code is as follows
String[] items = {not spicy,""slightly spicy,""medium spicy,""heavy spicy"};
AlertDialog.Builder dialog = new AlertDialog.Builder(InflateActivity.this); dialog.setIcon(R.mipmap.ic_launcher); dialog.setTitle("Hotness selection"); dialog.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(InflateActivity.this, items[which], Toast.LENGTH_SHORT).show(); } }); dialog.setCancelable(false); dialog.show();
Radio cartridge
Code
String[] items = {not spicy,""slightly spicy,""medium spicy,""heavy spicy"};
AlertDialog.Builder dialog = new AlertDialog.Builder(InflateActivity.this); dialog.setIcon(R.mipmap.ic_launcher); dialog.setTitle("Hotness selection"); dialog.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(InflateActivity.this, items[which], Toast.LENGTH_SHORT).show(); } }); dialog.setCancelable(false); dialog.show();
Multi-selection cartridge frame
String[] items = {not spicy,""slightly spicy,""medium spicy,""heavy spicy"};
AlertDialog.Builder dialog = new AlertDialog.Builder(InflateActivity.this); dialog.setIcon(R.mipmap.ic_launcher); dialog.setTitle("Hotness selection"); dialog.setMultiChoiceItems(items, new boolean[]{false,false,false,false}, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { } }); dialog.setCancelable(false); dialog.show();
This is the Alert Dialog style, similar to the circle and progress bar at the beginning of the proposed use of ProgressBar, and there are bullet boxes inside.
It is not recommended to add the input of the input box directly with getView, because when Dialog disappears, it is necessary to kill the addition of getView, otherwise the next time you come in.
A common diaolog exception occurs.
The next article will record the custom Dialog to achieve more effects...