Virtual Keyboard is lost after hiding it using IFMXVirtualKeyboardService

delphi, delphi-xe7, firemonkey

Solution

There is a very simple method to hide the virtual keyboard.

uses
{$IFDEF IOS}
  FMX.Forms
{$ENDIF}
{$IFDEF Android}
  Androidapi.JNI.Embarcadero,
  FMX.Platform.Android,
  FMX.Helpers.Android
{$ENDIF};

procedure HideVirtualKeyboard;
{$IFDEF IOS}
begin
  try
    Screen.ActiveForm.Focused := nil;
  except
  end;
end;
{$ENDIF}
{$IFDEF Android}    
var
  TextView: JFMXTextEditorProxy;
begin
  try
    begin
      TextView := MainActivity.getTextEditorProxy;
      CallInUIThread(
        procedure
        begin
          TextView.setFocusable(false);
          TextView.setFocusableInTouchMode(false);
          TextView.showSoftInput(false);
          TextView.clearFocus;
          TextView.setFocusable(true);
          TextView.setFocusableInTouchMode(true);
        end);
    end
  except
  end;
end;
{$ENDIF}

Problem

I have a `TEdit` and a `TTMSFMXWebGMaps` on my form. In my edit's `OnKeyUp()` event, I have this code to hide iPhone 4's virtual keyboard: ``` if TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService) then (TPlatformServices.Current.GetPlatformService(IFMXVirtualKeyboardService) as IFMXVirtualKeyboardService).HideVirtualKeyboard; ``` The problem is, I can not show the keyboard again without changing focus to another control. I tried this in my edit's `OnTap()`, but it does not bring the keyboard back: ``` if TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService) then (TPlatformServices.Current.GetPlatformService(IFMXVirtualKeyboardService) as IFMXVirtualKeyboardService).ShowVirtualKeyboard(edSearch); ``` And since my form only contains one `TEdit`, keyboard is lost forever unless the user navigates to another form and comes back. Any thoughts?

Original source