In Windows applications, we are often in order to allow users to quickly input, in the edit element in the onkeyup or OnKeyDown event to actively detect whether the user entered the character line is a newline symbol (enter), when the user presses ENTER, the code will actively put the cursor Focus goes to the next field, but in the mobile device, there is one more topic: "If you have multiple fields, take it to the next field." But if it's a single field, or the last field, hide the virtual keyboard "
The author of this topic in the 20,149-month note "Virtual Keyboard display and hide" inside has been introduced once, but was focused on the iOS system, because at that time I developed a platform mostly focused on iOS, the Android system is not much concern.
Recently in some projects, but also to reach the Android platform, but I still adhere to the "last minute, never speak Java" principle, know the author's friends are also aware that the author will write, but not forced to write the principles of java.
Plus Delphi from XE6, the support for Android is also very deep, the author is more able to strengthen this position.
Anyway, in the Tedit component to hide the virtual keyboard when the user presses the ENTER key of the virtual keyboard, how do you want to do it?
It was obvious that the 20,149-month approach (shifting focus to other components) didn't work on the Android platform, or I didn't have to write this note any more.
Yes, users who are familiar with Android know that by pressing the Android entity back button, they can hide the virtual keyboard. So this is also very simple, that is, "in the onkeyup event, you can change the key to 137."
In the OnKeyUp event, there are two call by Reference parameters, one is Key and the other is KeyChar, allowing us to re-assign the new value to the system after the keyboard event has been processed. In Delphi Seattle, Berlin, Tokyo (the previous version I have removed, cannot be verified), these three newer versions are defined with a value of Vkhardwareback, whose value is 137.
You can hide the keyboard by assigning 137 to Key in the OnKeyUp event, but often our code may be used on multiple platforms, so my sample code will have a discriminant like {$IFDEF Android} to facilitate the program maintenance of the platform:
It should be easy to understand, right?
In the Android text editing control (Tedit), how to press Enter to hide the virtual keyboard