首页 > 移动平台 > 详细

赵雅智_android_ui_dialog

时间:2014-06-05 12:41:29      阅读:367      评论:0      收藏:0      [点我收藏+]

运行效果:

bubuko.com,布布扣bubuko.com,布布扣

方法一

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,布布扣,bubuko.com

赵雅智_android_ui_dialog

原文:http://blog.csdn.net/zhaoyazhi2129/article/details/27383833

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!