鸟语天空
AlertDialog
post by:追风剑情 2015-12-24 17:10

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

         /**
	 * 退出游戏确认对话框
	 */
	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

 

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容