比Toast更友好的对话框AlertDialog
2013-12-19 18:44
141 查看
在调试过程中往往会弹出一个提示来提醒一个操作的状态,使用Toast时是会自动消失的,可能导致无法看到需要的信息。
而AlertDialog则是可以交互的对话框,使用起来更友好一些,一行代码的写法(与Toast相似的简洁哦~)
new AlertDialog.Builder(this).setTitle("Error").setMessage("Detail message.").setPositiveButton("OK", null).show();
当然还可以写的更复杂些:
new AlertDialog.Builder(this)
.setTitle("Warning")
.setMessage("Sure to reboot?")
.setNegativeButton("Cancel", null)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String cmd = "su -c reboot";
try {
Runtime.getRuntime().exec(cmd);
} catch (Exception e){
Toast.makeText(getApplicationContext(), "Error! Fail to reboot.", Toast.LENGTH_SHORT).show();
}
}
})
.show();
而AlertDialog则是可以交互的对话框,使用起来更友好一些,一行代码的写法(与Toast相似的简洁哦~)
new AlertDialog.Builder(this).setTitle("Error").setMessage("Detail message.").setPositiveButton("OK", null).show();
当然还可以写的更复杂些:
new AlertDialog.Builder(this)
.setTitle("Warning")
.setMessage("Sure to reboot?")
.setNegativeButton("Cancel", null)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String cmd = "su -c reboot";
try {
Runtime.getRuntime().exec(cmd);
} catch (Exception e){
Toast.makeText(getApplicationContext(), "Error! Fail to reboot.", Toast.LENGTH_SHORT).show();
}
}
})
.show();
相关文章推荐
- Android界面设计之对话框——定制Toast、AlertDialog
- Android界面设计之对话框——定制Toast、AlertDialog
- Android界面设计之对话框——定制Toast、AlertDialog
- android 带EditView(编辑框)的AlertDialog(对话框)及获取输入内容
- 在AlertDialog对话框中弹出软键盘
- Android checkbox和radiobutton 以及Toast和AlertDialog的使用
- 自定义 Android 对话框 (AlertDialog) 的样式
- 使用AlertDialog创建对话框的大致步骤
- Android:在AlertDialog点击按钮隐藏对话框
- Toast,AlertDialog的误解
- android 系统提示对话框(AlertDialog)的使用
- jQuery UI Dialog 创建友好的弹出对话框
- 【Android】对话框 AlertDialog
- 【转】Android AlertDialog 点击对话框外部区域不关闭的设置
- Android 系统提示对话框(AlertDialog)的使用
- 使用AlertDialog创建单选列表对话框
- android对话框alertDiaLog
- Android 对话框AlertDialog,PopupWindow使用大全
- Aandroid 学习之 AlertDialog窗口(具有交互功能的对话框)
- 【Android】对话框 AlertDialog