How can I make sure a window always showing above soft keyboard? - android

I add a view by WindowManager above soft keyboard with TYPE_APPLICATION_PANEL, but it doesn't work on some phones, neither TYPE_SYSTEM_ALERT. What should I do to make it happen on all phones?

TYPE_SYSTEM_ALERT windows do not work on some devices at all, but if they work they should be placed above the IME window. I would recommend you to try TYPE_TOAST windows. Toasts work on all devices and are shown above keyboard. But on some Android versions like 4.1 toasts do not accept user input such as touches or key events.
TYPE_PHONE might also be a good candidate for solving your problem but I think it will not work on devices where TYPE_SYSTEM_ALERT doesn't work.
UPDATE: Another thing you may try is to add WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM to WindowManager.LayoutParams.flags. This flag tells Android to position a window so that it can cover IME. In this case WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE flag must be unset. In this configuration the window will be focusable and should be positioned in front of IME.
Another option is to have just WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE flag set and WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM flag unset. It will also make your window positioned in front of IME but the window will not be focusable.

Related

How to get the Window of InputMethod on Android

In order to collect user's keystroke features on our App, I have to collect the touchevent(or just the click timestamp) on the input method view(soft keyboard).
1)As far as I know, the window of the soft keyboard is distinct from the window of the Activity
2)As long as I could get the window of a view, I can intercept the touch event of this window.
So is there a way to get the window of the soft keyboard?
As far as I know, the keyboard window belongs to system UI, like status bar or notification window; a common app has no access to such system windows in Android framework.
However you may try something tricky to to see if it would achieve your purpose: When the soft keyboard is launched, you can calculate its height and then create a new transparent window, like PopupWindow, with the same height covering the keyboard. This way you may be able to intercept the touch events on the keyboard without blocking them.
=== Updated 21/12/2018 ===
Please note that all windows in Android are actually implemented the similar way in ui framework. i.e. Your app's application window, InputMethod, Status Bar, Notification Bar... are all windows each with a flag to indicate the window type (read here). In short, window type will decide the window z-index when being rendered on the screen. They are categorised as Application Window, Sub-Window and System Window.
With that being said, PopupWindow is just one of them, a handy helper window provided by Android system (with a smaller z-index against the InputMethod window's). Just try to create your own window using WindowManager.addView() with some window type flag greater than the InputMethod window (which might be carrying a flag of TYPE_INPUT_METHOD).

Push up the layout when Keypad is enabled

I am using Collapsing ToolBar and Tab to make this layout. When the EditText cursor is enabled the entire activity has to be pushed up. Even here I used the same working code which is working good in an another app without Collapsing ToolBar. But here it is missed to work. Please help me.
This is the code that I used in another activity which is working good.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN |
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
From the WindowManager documentation:
SOFT_INPUT_ADJUST_PAN
Adjustment option for softInputMode: set to have a window pan when an input method is shown, so it doesn't need to deal with resizing but just panned by the framework to ensure the current input focus is visible.
Try setting the soft input mode to only WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE and see if that fixes your problem.

Difference between InputMethodManager SHOW_FORCED and SHOW_IMPLICIT in Android

I would like to know the behavioral difference of the constants SHOW_FORCED andSHOW_IMPLICIT. I tried both and couldn't see any difference in the first look.
SHOW_FORCED and SHOW_IMPLICIT work in tandem with the hiding methods HIDE_IMPLICIT_ONLY and HIDE_NOT_ALWAYS.
Using SHOW_FORCED indicates that the user has explicitly requested that the keyboard be shown (such as by pressing an "open keyboard" button), and thus the system should force it to open. In this case, any existing request to hide the keyboard using the above flags will be ignored (thus the keyboard is "forced" open).
Using SHOW_IMPLICIT means that your app thinks the user wants the keyboard open, but hasn't explicitly requested it. In this case, requests to hide the keyboard with HIDE_IMPLICIT_ONLY or HIDE_NOT_ALWAYS will still be respected.

android sdk custom keyboard not moving app

I think this issue was posted before. I'm having a custom keyboard and I need to make the app move above it like the softKeyboard with adjust does. Is it possible to do this? Can WindowManager help in any way?
if it's not possible, is it possible to assign a custom soft keyboard to an editbox in the app without prompting the user the dialog for choosing the custom soft keyboard?
Thank you
Can WindowManager help in any way?
WindowManager won't help here, but if you add your entire Keyboard layout to the end of your Activity's layout tree, it should push all other elements up. Using the WindowManager will allow you to "float" the keyboard above the rest of your View.
without prompting the user the dialog for choosing the custom soft keyboard?
This is not allowed for security reasons. You could override onTouch() for that EditText and show your own custom keyboard, but that's about all you can do.

adjust_pan behavior in Webview in fullscreen

I am trying to solve the issue that in my Webview, when a user selects a textfield, the keyboard that appears covers the text field below.
Instead, I need a behavior where the text field is moved right above the keyboard, like what the flag SOFT_INPUT_ADJUST_PAN would do.
Based on testing, it seems like by default on a Webview, it is displaying the keyboard below the field.
But my WebView is in fullscreen. I am calling this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN) in my activity);
and this seems to make android stop doing the default 'pan and scan' behavior.
I've tried to call
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
and even
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
but that did not fix it.
I need to set the activity to fullscreen because I want to hide both the title bar and the status bar, so removing it is not an option unless there is another way to hide the status bar.
Any idea on how to solve this issue?
Laurent
You need to remove FLAG_FULLSCREEN flag. There is a bug somewhere in the OS machinery and with some digging around i have found the following:
without any extra scroll view around web view adjustPan never worked for me. Unfortunatelly the add scroll view also not always helps.
adjustScroll works for me when FLAG_FULLSCREEN is not present for the activity the webview is in.
So to sum it up the safest option to go with when it comes to WebView is adjustResize not full screen activity.
For me this worked:
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Categories

Resources