赵雅智_android_ui_dialog
2014-05-28 22:21
141 查看
运行效果:
方法一
public void openDialog(View v) { // 打开一个对话框 // 构建者对象 AlertDialog.Builder builder = new Builder(this); // 构建者创建一个对话框 AlertDialog alertDialog = builder.create(); // 设置对话框的标题 alertDialog.setTitle("我是对话框"); // 设置对话框内容 alertDialog.setMessage("你是否真的要退出程序?"); // 设置对话框的图标 alertDialog.setIcon(R.drawable.ic_launcher); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_LONG).show(); } }); alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "中立", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "中立", Toast.LENGTH_LONG).show(); } }); alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_LONG).show(); } }); //必须设置 alertDialog.show(); }
方法2
public void openDialog(View v) { new AlertDialog.Builder(this).setTitle("我是对话框").setMessage("你是否真的要退出程序") .setIcon(R.drawable.ic_launcher).setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_LONG).show(); } }).setNeutralButton("中立", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "中立", Toast.LENGTH_LONG).show(); } }).setNegativeButton("取消", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_LONG).show(); } }).create().show(); }
方法3
新建一个activity,在AndroidMenifest.xml中设置Theme主题android:theme="@android:style/Theme.Dialog"
相关文章推荐
- Android UI系列-----Dialog对话框
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- android ui定义自己的dialog
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- 赵雅智_AndroidUI_listview的item滑动删除效果
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog) 推荐
- Android UI系列-----Dialog对话框
- android ui定义自己的dialog(项目框架搭建时就写好,之后事半功倍)
- Android UI控件详解-Dialog(对话框合集)
- Android UI系列-----Dialog对话框
- Android笔记:Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android学习:用户界面UI之AlertDialog
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android 开发之自定义Dialog及UI的实现
- Android UI【android 自定义dialog 多选项对话框】
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)2010-06-16 18:17:21
- Android UI设计之<七>自定义Dialog,实现各种风格效果的对话框
- Android UI控件系列:Dialog(对话框)