android - show Dialog在锁定屏幕上设置活动而不解锁

时间:2016-05-22 15:56:39

标签: android popup themes popupwindow android-dialog

当某些事件发生时屏幕被锁定时,我会显示一个弹出屏幕。

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}

问题是 - 在经历了很多挫折之后我发现了answer,说当activity使用Theme.Dialog时这不起作用。

我希望我的活动全屏,它假设或多或少像短信弹出通知。如果没有Theme.Dialog主题,我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

不确定这是否是您正在寻找的东西,但这会在窗口中弹出一切为我弹出:

代码的关键部分是'WRAP_CONTENT':

    WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    View mView = View.inflate(getApplicationContext(), R.layout.dialogue_page, null);
    WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, 0, 0,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            PixelFormat.RGBA_8888);
    mWindowManager.addView(mView, mLayoutParams);