你能帮我在TEDIT对焦时如何隐藏(并再次显示)软键盘吗?

最佳答案

我有一个解决方案:
在.dpr中,将vkautoshowmode设置为never

begin
  Application.Initialize;
  VKAutoShowMode := TVKAutoShowMode.Never;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

在窗体上显示软键盘(例如在tedit.onenter事件上):
var
  FService: IFMXVirtualKeyboardService;
begin
  TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService));
  if (FService <> nil) then
  begin
    FService.ShowVirtualKeyboard(Edit1);
    Edit1.SetFocus;
  end;

在窗体上隐藏软键盘(Edit1仍将使用隐藏的软键盘聚焦):
var
  FService: IFMXVirtualKeyboardService;
begin
  TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService));
  if (FService <> nil) then
  begin
    FService.HideVirtualKeyboard;
    Edit1.SetFocus;
  end;

07-27 23:45