Hai nguyen thanh
Hai nguyen thanh

Reputation: 728

How to draw over other apps but under keyboard?

I'm working on a floating app that draws a bubble on the screen. I want to make the bubble always under the keyboard when it appear or at least catching keyboard event.

Here is the parameter code I use to add the bubble to the window manager:

         params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 
                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
                PixelFormat.TRANSLUCENT);

I have tried all window type/flag but can't make it happen. I know this is possible because the "EAS: easy app switcher" did it.

I really hope that somebody out there could enlighten me on this. Thanks in advance for your time!

Upvotes: 3

Views: 679

Answers (1)

Phocacius
Phocacius

Reputation: 1148

I just had the same problem and finally found the solution. Although it probably won't help you anymore, hopefully it will help someone else with the same problem.

The flag needed is WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM in combination with WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE.

This is what the javadoc tells about the flag:

    /** Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with
     * respect to how this window interacts with the current method.  That
     * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the
     * window will behave as if it needs to interact with the input method
     * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is
     * not set and this flag is set, then the window will behave as if it
     * doesn't need to interact with the input method and can be placed
     * to use more space and cover the input method.
     */

Upvotes: 2

Related Questions