Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

android - How to display a fullscreen TYPE_SYSTEM_ALERT window?

I'm currently having a hard time displaying a TYPE_SYSTEM_ALERT window in fullscreen mode. I'd like to do so in order to have an overlay view, created from a service, on top of the status bar but without hiding it.

However, putting the FLAG_FULLSCREEN flag in the layout params of the window I'm creating doesn't seem to work. I found the STATUS_BAR and EXPAND_STATUS_BAR permissions but I couldn't find how to make use of them.

Here are the LayoutParams :

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            PixelFormat.TRANSLUCENT);

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

    mWindowManager.addView(mOverlayView, params);

Any ideas?

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found the solution while trying to do something else!

In order to have a TYPE_SYSTEM_ALERT window on top of every other window AND on top of the status bar you must add the FLAG_LAYOUT_IN_SCREEN flag and not the FLAG_LAYOUT_FULLSCREEN flag :

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
        WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
        PixelFormat.TRANSLUCENT);

mWindowManager.addView(mOverlayView, params);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...