Delphi FMX - Virtual Keyboard in Android covers control (invalid keyboard height)

4.6k views Asked by At

I have created a simple FMX form (in Delphi Tokyo 10.2.1) with 3 controls on it:

  1. TLayout (LayoutKbd) - aligned to the bottom of the screen. Height 1.
  2. TRectangle - aligned to bottom (above the TLayout). Height 5.
  3. TMemo - aligned to client.

In the Form's OnVirtualKeyboardShown event, I have the following code:

procedure TForm1.FormVirtualKeyboardShown(Sender: TObject;
  KeyboardVisible: Boolean; const Bounds: TRect);
begin
  if KeyboardVisible then
  begin
    LayoutKbd.Height:=Bounds.Height;
  end;
end;

When I run it on my Android phone and touch inside the memo, the virtual keyboard is shown and the event is triggered. However the value of Bounds.Height is a random, large, negative number (see local var during debug) below.

enter image description here

As per the documentation:

The Bounds parameter of the event handler specifies the screen coordinates of the window of the virtual keyboard

I would expect the screen to show me the keyboard (overlapping my TLayout) and above it the TRectangle and above that my TMemo. But since the height of the layout is not being shown, the virtual keyboard covers part of the memo.

It is possible I am missing something very basic. My questions are:

  • How do I get the height of the virtual keyboard?
  • Am I doing something wrong with trying to get the height from the Bounds? (I have also tried getting the height from Bounds.Size.Height - which does not work either)
  • Is there a different/better way to reliably resize my memo so that none of it is obscured by the virtual keyboard.

Appreciate any help or guidance in this matter.

UPDATE 20170906: Given the generally poor experience I have had with 10.2.1 Tokyo, I decided to try the code in 10.1.2 Berlin. Interestingly, the code works in Berlin - but the height of the keyboard is reported to be exactly 25px more than it should be. So by using LayoutKbd.Height:=Bounds.Height - 25;, I get the exact height of the keyboard. While this is still an issue (related to RSP-14004), it is something that can be worked with.

So this does seem like a bug with Tokyo 10.2.1 - I have filed a ticket on Quality Portal (RSP-19001). I am growing increasingly frustrated with the quality issues surrounding Tokyo 10.2.1. We are spending a lot of money on Delphi and Embarcadero really needs to get its act together when pushing out major releases so that it is at least relatively bug-free. Tokyo seems to be very unreliable...

UPDATE 20171201: For Android, I would very highly recommend the KastriFree library by Dave Nottage which implements a simple and easy to use message based notification mechanism. I have been using it in my Android app, and it works flawlessly!

0

There are 0 answers