Delphi Firemonkey manage VirtualKeyboard on mobile applications
In Firemonkey you can manage the virtualkeyboard on your mobile applications.
if you need that the keyboard not autoshow in your application when a text box is selected you can add this code:
1 2 3 4 |
// uses FMX.Types // you can set TVKAutoShowMode = (DefinedBySystem, Never, Always); FMX.Types.VKAutoShowMode :=TVKAutoShowMode.vkasNever; |
obviusly to enable the virtual keyboard:
1 2 3 4 |
// uses FMX.Types // you can set TVKAutoShowMode = (DefinedBySystem, Never, Always); FMX.Types.VKAutoShowMode :=TVKAutoShowMode.DefinedBySystem; |
so if you have the virtualkeyboard enabled and you want to hide when and edit control is focused you can use this procedure that i found in stackoverflow AT THIS LINK:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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} |
ANOTHER WAY IS TO USE THE EMBARCADERO PLATFORMSERVICE:
1 2 3 4 5 6 7 |
if TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService,Keyboard) then begin if TVirtualKeyBoardState.Visible in Keyboard.GetVirtualKeyBoardState then begin Keyboard.HideVirtualKeyboard; end end; |
When you connect a bluethoot or usb barcode reader, or a phisycal keyboard to your Android device, your application never show the virtualkeyboard if you don’t change some settings on Android.
Tho show the virtualkeyboard even you have a barcode scanner connected you need to change this settings:
On Android 5.0
Languages and Input > Current keyboard > Turn “Hardware Show Input Methods” ON
On Android 8.0 and Higher
System > Languages and Input > Physical Keyboard > Turn “Show virtual keyboard” ON
If your system is in Italian go to:
Impostazioni –> Gestione Generale –> Lingua e Inserimento –> Tastiere Fisica –> Mostra tastiera su schermo