当我们覆盖主页按钮操作时,透明活动不可见

时间:2012-06-28 05:57:04

标签: android

我在Android应用程序中工作,我的方案是在活动上方显示透明活动,并通过添加

成功实现了它

android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"

在我的活动清单中。但我也想覆盖我的Android设备硬件主页按钮。所以我已经覆盖了关键事件dispatchKeyEventonAttachedToWindow,并且我已成功实现了这一点。但是,当我覆盖主页按钮键时,此透明活动不可见。我用来覆盖主键事件的代码是

@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();

    }

将这两者结合在一起的任何解决方案。 在此先感谢。

0 个答案:

没有答案