Android 覆盖主页按钮操作时,透明活动不可见
我在一个android应用程序中工作,我的场景是在活动上方显示一个透明的活动,我通过添加 android:theme=@android:style/theme.transparent.NoTitleBar.Fullscreen 在我的清单中,在那个活动中。但我也想覆盖我的android设备硬件主页按钮。因此,我已经覆盖了关键事件dispatchKeyEvent和onAttachedToWindow,并成功地实现了这一点。但是,当我覆盖了home按钮键时,这个透明的活动就不可见了。我用来覆盖home key事件的代码是 : 任何将这两者结合起来的解决方案。Android 覆盖主页按钮操作时,透明活动不可见,android,Android,我在一个android应用程序中工作,我的场景是在活动上方显示一个透明的活动,我通过添加 android:theme=@android:style/theme.transparent.NoTitleBar.Fullscreen 在我的清单中,在那个活动中。但我也想覆盖我的android设备硬件主页按钮。因此,我已经覆盖了关键事件dispatchKeyEvent和onAttachedToWindow,并成功地实现了这一点。但是,当我覆盖了home按钮键时,这个透明的活动就不可见了。我用来覆盖hom
提前感谢。无法覆盖主密钥,请探索有关主密钥覆盖功能的更多信息。但我能够通过上述代码覆盖主密钥事件。请检查该代码。但并非所有版本都能做到这一点。。
@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();
}