A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout.
Building an Alert Dialog
The AlertDialog class allows you to build a variety of dialog designs and is often the only dialog class you’ll need.
There are three regions of an alert dialog:
Title: This is optional and should be used only when the content area is occupied by a detailed message, a list, or custom layout. If you need to state a simple message or question you don’t need a title.
Content area:This can display a message, a list, or other custom layout.
Action buttons:There should be no more than three action buttons in a dialog.
The AlertDialog.Builder class provides APIs that allow you to create an AlertDialog with these kinds of content, including a custom layout.
Adding buttons
To add action buttons call the setPositiveButton() and setNegativeButton() methods.
The set…Button() methods require a title for the button (supplied by a string resource) and a DialogInterface.OnClickListener that defines the action to take when the user presses the button.
There are three different action buttons you can add:
Positive:-You should use this to accept and continue with the action (the “OK” action).
Negative:-You should use this to cancel the action.
Neutral:-You should use this when the user may not want to proceed with the action, but doesn’t necessarily want to cancel. It appears between the positive and negative buttons. For example, the action might be “Remind me later.”
Comments
Post a Comment