状态栏和叠加层

时间:2016-01-11 18:21:23

标签: android

我正在使用此参数显示自定义叠加层,从服务中扩展视图:

params = new WindowManager.LayoutParams(WindowManager
        .LayoutParams
        .MATCH_PARENT,
        statusBarHeight, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager
        .LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
        | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams
        .FLAG_NOT_FOCUSABLE, 0);
params.gravity = Gravity.CENTER | Gravity.TOP;

问题在于,如果状态栏已展开,则叠加层将位于快速设置菜单上。我怎么能避免这种情况?我正在使用android 6。

1 个答案:

答案 0 :(得分:1)

而不是 TYPE_SYSTEM_OVERLAY 使用 TYPE_SYSTEM_ERROR

params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            100,
            // Allows the view to be on top of the StatusBar
            WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
            // Keeps the button presses from going to the background window
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
            // Enables the notification to recieve touch events
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
            // Draws over status bar
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
            PixelFormat.TRANSLUCENT);

params.gravity =  Gravity.TOP|Gravity.CENTER;      

mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mView, mLP);

这可以解决您的问题。