Android 返回键

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event)
	{
		// 按下键盘上返回按钮
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && MainActivity.this.isTaskRoot())
		{
			new AlertDialog.Builder(this).setIcon(R.drawable.icon).setTitle("Exit").setMessage("Exit.....?")
					.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
					{
						@Override
						public void onClick(DialogInterface dialog, int which)
						{
						}
					}).setPositiveButton("Confirm", new DialogInterface.OnClickListener()
					{
						public void onClick(DialogInterface dialog, int whichButton)
						{
							finish();
						}
					}).show();
			return true;
		} else
		{
			return super.onKeyDown(keyCode, event);
		}
	}

你可能感兴趣的:(android)