android dialog home键

在一个界面弹出AlertDialog后屏蔽home键

AlertDialog dialog = builder.create();
		dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

			@Override
			public boolean onKey(DialogInterface dialog, int keyCode,
					KeyEvent event) {
				// TODO Auto-generated method stub
				if (keyCode == KeyEvent.KEYCODE_HOME)
					return true;
				return false;
			}
		});
		dialog.show();
		dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);

  

public class BaseProgressDialog extends ProgressDialog {

	public BaseProgressDialog(Context context) {
		super(context);
		setOnShowListener(new DialogInterface.OnShowListener() {

			@Override
			public void onShow(DialogInterface dialog) {
				// TODO Auto-generated method stub
				getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
			}
		});
	}

	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		// TODO Auto-generated method stub
		switch (event.getKeyCode()) {
		case KeyEvent.KEYCODE_HOME:
			return true;
		}
		return super.dispatchKeyEvent(event);
	}

	public static BaseProgressDialog show(Context context, CharSequence title,
			CharSequence message) {
		BaseProgressDialog dialog = new BaseProgressDialog(context);
		dialog.setTitle(title);
		dialog.setMessage(message);
		dialog.setIndeterminate(false);
		dialog.setCancelable(false);
		dialog.setOnCancelListener(null);
		dialog.show();
		return dialog;
	}
}

 

你可能感兴趣的:(android dialog home键)