Zhou Hongbo
Zhou Hongbo

Reputation: 1515

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? enter image description here

Upvotes: 0

Views: 864

Answers (1)

Wei WANG
Wei WANG

Reputation: 1776

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).

Upvotes: 1

Related Questions