Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidC++BuilderCode SnippetDelphiDemoFiremonkeyIOSLibrary

Keep Controls Visible When Virtual Keyboard Pops Up In Delphi 10.2 Tokyo On Android And IOS

One thing that can really add polish to your application is setting it up so that when an edit field receives focus it automatically appears above the keyboard on mobile devices. If this is not done the keyboard can sometimes cover the edit field so you are unable to see what you are typing. There are a number of different ways to do this in Delphi 10.2 Tokyo (and previous versions).  We’ve written about this before can you can check out those posts here and here. There is also an example from Embarcadero called FMX.ScrollableForm on how to do this. The ScrollableForm example works well and I have used it in the past. However, in Delphi 10.2 Tokyo and Delphi 10.2.1 Tokyo it does not work quite right on Android. Developer Dave Nottage has come up with a solution to this problem and provided some source code to fix it. First you need his free library from GitHub called Kastri Free. Next he posted some code to use with the library to make it all happen. Here is the code snippet:

//
//
// Include System.Messaging in the uses clause
 
type
  TForm1 = class(TForm)
  private
    procedure VirtualKeyboardRectChangeMessageHandler(const Sender: TObject; const M: TMessage);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;
 
...
 
uses
  DW.Messaging, DW.VirtualKeyboard.Helpers;
 
constructor TForm1.Create(AOwner: TComponent);
begin
  inherited;
  TMessageManager.DefaultManager.SubscribeToMessage(TVirtualKeyboardRectChangeMessage,
VirtualKeyboardRectChangeMessageHandler);
end;
 
destructor TForm1.Destroy;
begin
  TMessageManager.DefaultManager.Unsubscribe(TVirtualKeyboardRectChangeMessage,
VirtualKeyboardRectChangeMessageHandler);
  inherited;
end;
 
procedure TForm1.VirtualKeyboardRectChangeMessageHandler(const Sender: TObject; const M: TMessage);
var
  LRect: TRect;
begin
  LRect := TVirtualKeyboardRectChangeMessage(M).Value;
  // LRect now contains the actual rect of the VK
end;

The full source code is available in a forum thread on the Embarcadero Forums site. You can head over there and see the full thread. The source code is mainly for Android but probably also works on IOS. I would assume it is not meant for Windows, OSX, or Linux. The Kastri Free library also has a lot of other functionality you can check out as well.

Check out the full forum thread about keeping the focused edit box visible on Android in Delphi 10.2 Tokyo.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts
DelphiDemoFiremonkeyLinuxOSXShowcaseWindows

AutoBlogAI: FireMonkey Client To Leverage LLMs And Generative AI For Blogging

DelphiFiremonkeyShowcaseUtilityWindows

Unleashing Creativity With Song Writer AI: A Deep Dive

DelphiFiremonkeyShowcaseWindows

How To Build Stable Diffusion Text To Image Prompts

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

Sign up for our Newsletter and
stay informed

Leave a Reply