重写Activity的onAttachedToWindow 方法
@Override public void onAttachedToWindow() { System.out.println("Page01 -->onAttachedToWindow"); this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); super.onAttachedToWindow(); }
监听OnKey事件
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { System.out.println("Page01 -->onKeyDown: keyCode: " + keyCode); if (KeyEvent.KEYCODE_HOME == keyCode) { System.out.println("HOME has been pressed yet ..."); // android.os.Process.killProcess(android.os.Process.myPid()); Toast.makeText(getApplicationContext(), "HOME 键已被禁用...", Toast.LENGTH_LONG).show(); } return super.onKeyDown(keyCode, event); // 不会回到 home 页面 }
时间: 2024-10-17 06:18:33