码迷,mamicode.com
首页 > 移动开发 > 详细

赵雅智_android_ui_dialog

时间:2014-06-07 01:14:00      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:android ui

运行效果:

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

标签:android ui

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!