我在一个android应用程序中工作,我的场景是在一个活动上方显示一个透明的活动,我已经通过添加成功实现了它
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
在我在那次活动中的清单中。但我也想覆盖我的 android 设备硬件主页按钮。因此,我已经覆盖了关键事件dispatchKeyEvent
,onAttachedToWindow
并且我已经成功地实现了这一点。但是当我覆盖主页按钮时,这个透明的活动是不可见的。我用来覆盖主页键事件的代码是
:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
onAttachedToWindow();
if ((event.getKeyCode() == KeyEvent.KEYCODE_HOME)) {
// if Home button is pressed EntryValidationActivity called
SharescreenActivity.this.finish();
Intent screenLockIntent = new Intent(SharescreenActivity.this,
EntryValidationActivity.class);
startActivity(screenLockIntent);
this.moveTaskToBack(true);
return true;
} else
return super.dispatchKeyEvent(event);
}
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
//this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onAttachedToWindow();
}
将这两者结合在一起的任何解决方案。提前致谢。