重写两个方法
@Override public void onAttachedToWindow() { this.getWindow().setType( WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); super.onAttachedToWindow(); } @Override public boolean dispatchKeyEvent(KeyEvent event) { // TODO Auto-generated method stub if(event.getKeyCode() == KeyEvent.KEYCODE_HOME) { Toast.makeText(this, "a", Toast.LENGTH_SHORT).show(); } //使用转到桌面代码 ntent mHomeIntent = new Intent(Intent.ACTION_MAIN, null); mHomeIntent.addCategory(Intent.CATEGORY_HOME); mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); startActivity(mHomeIntent); return super.dispatchKeyEvent(event); }此代码从2.3之后好像就没用了
版权声明:本文为博主原创文章,未经博主允许不得转载。