【问题标题】:Virtual Keyboard is lost after hiding it using IFMXVirtualKeyboardService使用 IFMXVirtualKeyboardService 隐藏虚拟键盘后丢失
【发布时间】:2015-04-20 18:58:28
【问题描述】:

我的表单上有一个TEdit 和一个TTMSFMXWebGMaps。在我编辑的OnKeyUp() 事件中,我有这段代码来隐藏 iPhone 4 的虚拟键盘:

if TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService) then
      (TPlatformServices.Current.GetPlatformService(IFMXVirtualKeyboardService) as IFMXVirtualKeyboardService).HideVirtualKeyboard;

问题是,如果不将焦点更改为另一个控件,我就无法再次显示键盘。我在我的编辑OnTap() 中尝试了这个,但它并没有把键盘带回来:

  if TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService) then
    (TPlatformServices.Current.GetPlatformService(IFMXVirtualKeyboardService) as IFMXVirtualKeyboardService).ShowVirtualKeyboard(edSearch);

由于我的表单只包含一个TEdit,因此除非用户导航到另一个表单并返回,否则键盘将永远丢失。有什么想法吗?

【问题讨论】:

  • 你不能做一个切换按钮来启用和禁用虚拟键盘。
  • @Remi No. 从用户的角度考虑
  • 我不太明白你想做什么。你想只在第一次之后显示键盘吗?
  • @Remi 我希望能够随意显示/隐藏键盘。目前,我可以隐藏键盘,但我不能再次显示它
  • 好的,但您究竟什么时候不想显示和隐藏它?你能给出更详细的解释吗?

标签: delphi firemonkey delphi-xe7


【解决方案1】:

有一个非常简单的方法可以隐藏虚拟键盘。

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}

【讨论】:

  • 我的 delphi 无法识别 JFMXTextEditorProxy,因为我确实使用了 Androidapi.JNI.Embarcadero,知道吗?
猜你喜欢
  • 1970-01-01
  • 2010-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多