http://developer.android.com/guide/topics/ui/dialogs.html
- Dialog Categories
- Dialog
- AlertDialog
- Add lists
- Add checkbox
- Add radio button
- ProgressDialog
- DatePickerDialog
- TimePickerDialog
- Floating Activity
- Customize Dialog
- Floating Activity
- Add
to the floating activity in AndroidManifest.xml
- Create dialog
- Activity as dialog
- Create a system dialog(such as AlertDialog, DatePickerDialog etc)
public void onCreate(xx)
{
super.onCreate(xxx);
setVisible(false);
showDialog(xxx);
}
public Dialog createDialog(xxx)
{
ProgressDialog dialog = new ProgressDialog (this);
dialog.setTitle(xxx);
dialog.setMessage(xxx);
return dialog;
}
- Floating dialog
Intent intent = new intent();
intent.setAction(xxx);
intent.addCagetory(xxx);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_EXCLUDE_FROM_RECENTS);
or
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent); - xxx
- AlertDialog
- Create AlertDialog
Dialog dialog = new AlertDialog.Builder(context).setMessage(xxx).setTitle(xxx)
- Customize AlertDialog
LayoutInflater inflater = (LayoutInflater)context.getSystemServiceContext.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.xxx, null);
AlertDialog.Builder(context).setView(view);
- Issue
- [Q]: When Alert dialog is shown, press Search key, dialog will dismiss, and application ui will be hidded, when you launch application from History or Program list, it can not be launched again uless reboot device, or kill application and then launch it again.
[A]: The solution is to register key listener to block Search key event when to create dialog with AlertDialog.Builder, i.e.
new AlertDialog.Builder(context).setOnKeyListener(new DialogInterface.OnKeyListener(
{
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_SEARCH)
{
return true;
}
else
{
return false;
}
}
});
- Android custom Dialog
(From: http://blog.androgames.net/10/custom-android-dialog/)
- Specify title from resource or String
- Specify content from resource, String or custom layout
- Set positive and negative buttons and associated listeners
- xxx
- Remove dialog
A dialog will not be destroyed when if is closed, it is keept to be used in the future, when you call showDialog to show that dialog again, the dialog is shown without to create a new one, if you want to the dialog to be destroyed when it is closed, just to invoke removeDialog(). But if you want to update contents of the dialog, just override onPrepareDialog and do something here.
- FAQ
- You are unable to show the same dialog with Activity.showDialog in its lisenter function, such as OnCanceListener\OnDismissListener\OnShowListener
- If you show a dialog, and then start an Activity immediately, the alert can't be shown sometimes.
- How to show dialog
There are 2 ways:
- Invoke showDialog in Activity, and then override onCreateDialog, sometimes, you need to override onPrepareDialog also.
- New dialog, then call Dialog.show();
- Prevent alert dialog from being dismissed once button is clicked
dialog.setButton(ProgressDialog.BUTTON_NEGATIVE,
getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.show();
final Button cancelButton =
dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// handle the click
}
});
Its important to only call getButton() after show() has been called,
or it will return null.
- xxx
- ...
阅读(1159) | 评论(0) | 转发(0) |