屏蔽 Home 按键,至少做到两点:
1) 重写 onAttachedToWindow
2)重写 onKeyDown
@Override public void onAttachedToWindow() { super.onAttachedToWindow(); getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); Log.d("mark", "onAttachedToWindow-- "); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_HOME: Toast.makeText(this, "home key is pressed", 1).show(); break; } } return super.onKeyDown(keyCode, event); }
http://blog.csdn.net/androidbluetooth/article/details/7396665
时间: 2024-10-22 03:35:28