AlertDialog

作者:追风剑情 发布于:2015-12-24 17:10 分类:Android

示例一: 确认/取消 对话框

         /**
	 * 退出游戏确认对话框
	 */
	public void exitGameDialog(String title, String message, String positiveButton, String negativeButton, boolean cancel)
	{
		AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton(positiveButton, new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				MainActivity.this.finish();
			}
		});
		
		if(cancel){//需要显示取消按钮
			builder.setNegativeButton(negativeButton, new OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});
		}
		
		builder.create().show();
	}

运行效果

11.png

 

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号