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).
Related
I have a very simple UI that has one entry control to enter phone number and a button. The entry control has a handler for removing border around it. When the entry control got focus, keyboard pops up. But when I try to tap outside the entry control such as on the screen empty area, the keyboard does not dismiss and the entry control does not lose focus. Also since the button is at the bottom of the screen, therefore, the soft keyboard hides it and there is no way to tap the button. The button can only be tapped if I press the Android device back button.
At present, I have not checked this behavior on an iOS device.
This was not a problem in Xamarin Forms though. I searched a lot on Internet and found that it is currently a bug in MAUI.
I tried to attach a tap gesture on the parent layout control and invoked platform-specific code to hide the keyboard but it seems the entry does not lose focus and in turn the tap gesture event is never called.
However, the entry control should lose focus automatically when I tap outside the entry control (such as on the screen) and the soft keyboard should automatically dismiss.
Please provide a workaround if there is any.
Known bug. Removing the focus sometimes helps. Sometimes you need to do Disable/Enable in sequence. (I go with the second).
If you want, you can read this for example:
https://github.com/dotnet/maui/issues/12002
(Most disturbing part, considering this is know bug for half year+)
We can leave the behavior how this is for now in NET7 and provide an
API in NET8 that lets users toggle this behavior on/off for iOS and
Android
I make application on C++/Qt for Android. It has only one QMainWindow and one Activity. But the window is smaller than screen size. It is placed in top left corner. I get events in window but I cannot find the way how pass events to activities visible outside my app window. Looks like window is modal. How can I solve this for Qt application?
To display a window on top of the status bar (and accept touch events), it seems TYPE_SYSTEM_ERROR is the only way to go.
However, such a window will also appear on the lock screen, which I do not want to happen.
Is there some other way to achieve this?
If not, is there a way to listen to the event where the lockscreen becomes visible, so that I can hide the window programmatically?
Please note: the app does not have an Activity context.
I have little (read: no) experience with animations in Android, but wanted to implement an animation for when the keyboard appears. Effectively, it would appear that the entire activity was sliding upwards (like the keyboard was below the activity and pushed it upwards), as opposed to only moving up so far as the selected EditText.
Does anyone know how to do this?
In the latest version of Android OS (Android version 11), they added new set of APIs let you synchronize your app’s content with the IME (input method editor, aka soft keyboard) and system bars as they animate on and offscreen, making it much easier to create natural, intuitive and jank-free IME transitions.
WindowInsetsAnimation.Callback
For frame-perfect transitions, a new insets animation listener notifies apps of per-frame changes to insets while the system bars or the IME animate.
WindowInsetsAnimationController
Apps can take control of the IME and system bar transitions through the WindowInsetsAnimationController API.
An app receives no notification of when a keyboard appears, and the android framework itself is responsible for either sliding the app or laying it out again. So customization isn't really possible. Which is probably a good thing- a keyboard is a separate app, and having written one I wouldn't want to even try to write the keyboard half of such an animation, we'd never get it to look right with all the various ways the app could do it.
The closest you'll get is to specify the fields to pan rather than resize when the keyboard is opened.
I want to show the Android version of a Model Dialog with text input however I think the keyboard will be behind the actual activity since dialogs weren't made to have inputs. Is there any way I can get the keyboard to show in an actual dialog.
I did see this SO question -- however I'd rather not use an Theme.Dialog'ed activity because I feel like an activity would be too heavy for my purposes. How can I show this Model Dialog with the keyboard input in the foreground?
This is what I am talking about:
Who said dialogs aren't made to have inputs?! A dialog can contain anything - text, buttons, progress bars, input fields. Did you try it out? A keyboard resizes your canvas, so there's no "behind"/"front" going on. (Besides, you can always summon the IME on a phone without a QWERTY
keyboard by holding the menu button - even there's a modAl dialog.)
EDIT: If you need proof, just look at the API Demos (App -> Dialog). There's an example for a dialog with text entry. Source code here: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlertDialogSamples.html (DIALOG_TEXT_ENTRY)