How to make your Android virtual keyboard visible/invisible while Tedit is in focus

Asked

Viewed 3,550 times

2

I use Delphi XE7, wanted to know how to treat this issue, Seto the focus on TEdit, it opens the virtual keyboard Android, Press the back it closes the keyboard and the focus stays on the TEdit, but when I press again on Tedit while it’s in focus it no longer opens the virtual keyboard.

Does anyone have any idea how to solve?

3 answers

3


I have no way to test it now, but try the following code on OnEnter edit’s:

procedure TForm1.Edit1Enter(Sender: TObject);
var
  VKbSvc: IFMXVirtualKeyboardService;
begin    
  if TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, VKbSvc) then
  begin
      VKbSvc.ShowVirtualKeyboard(Edit1);
  end;
end;
  • It didn’t help, because Tedit is already in focus, it has a way of checking if Tedit itself is in focus, so I could check and then open the keyboard is an idea.

  • You said in the question "when I put the focus back". If Tedit already has the focus, try to put the code in the OnClick or OnTap tedit.

  • "when I refocus on Tedit while it’s in focus, "it’s no use, I’ve tried.

  • edited the question, I was not clear. I’m sorry.

  • Try the following code on OnClick edit1.resetfocus; edit1.setfocus; and keep the code of OnEnter

  • 1

    I managed to solve, using the same idea that you gave me, instead of putting it on Onclick, I used the Onmouseenter event to open the keyboard and Onexit to close the keyboard, in Viewsource in the project I set up Vkautoshowmode := Tvkautoshowmode.Never, so I can control the keyboard when it should be closed and open. Thanks for the help

Show 1 more comment

3

Try using the global variable VKAutoShowMode := TVKAutoShowMode.vkasAlways, so that the keyboard always appears. Also be sure to include Unit FMX.Types in the project, as this global variable resides.

  • 2

    your suggestion gave an idea of I control the virtual keyboard, when it should be closed or open, in the Viewsource of the project, I set up the Vlautoshowmode :=Tvkautoshowmode.Never. Thanks for the help.

1

I have no way to test now, but try the following code in Edit’s Onenter:

procedure TForm1.Edit1Enter(Sender: TObject); var   VKbSvc: IFMXVirtualKeyboardService; begin       if TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, VKbSvc) then   begin
      VKbSvc.ShowVirtualKeyboard(Edit1);   end; end;

Complementing the colleague’s solution, to use this it is necessary to put FMX.VirtualKeyboard and FMX.Platform in imports(uses).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.