Xamarin.Forms
                                
                                
                                
                                    Xamarin.Forms copied to clipboard
                            
                            
                            
                        [Bug] Keyboard not hiding while focusing the entry programmatically.
Description
Keyboard not hiding while focusing the entry programmatically even ShowSoftInputOnFocus as false.
I want to hide the keyboard when attaching the hard keyboard so I tried to disable the soft keyboard always when the hard keyboard attached.
Steps to Reproduce
- Create a CustomEntry.
 - In the custom entry renderer, set the SetSoftInputMode as StateAlwaysHidden and disable the ShowSoftInputOnFocus
 - In the button click, call the entry.Focus method
 
Expected Behavior
Soft keyboard should not show while focusing the entry control.
Actual Behavior
Keyboard showing while focusing the entry control. If I manually focus the entry I am
Basic Information
- Version with issue: Xamarin forms : 5.0.0.0.2196
- Android: Target Framework 13
 
 - NuGet Packages: Xamarin forms : 5.0.0.0.2196
 - Affected Devices:
 
Environment
Visual Studio Enterprise 2022 for Mac Version 17.6.6 (build 408) Installation UUID: 9c46f919-7695-4fee-86e5-0429a28b92df
Xamarin Designer Version: 17.6.3.9 Hash: 2648399ae8 Branch: remotes/origin/d17-6 Build date: 2023-10-23 17:41:00 UTC
Xamarin.Android Version: 13.2.2.0 (Visual Studio Enterprise) Commit: xamarin-android/d17-5/45b0e14 Android SDK: /Users/localuser/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 12.1 (API level 32) 10.0 (API level 29) 13.0 (API level 33)
Android SDK Manager Version: 17.6.0.50 Hash: a715dca Branch: HEAD Build date: 2023-10-23 17:41:04 UTC
Operating System Mac OS X 12.5.0 Darwin 21.6.0 Darwin Kernel Version 21.6.0 Sat Jun 18 17:07:22 PDT 2022 root:xnu-8020.140.41~1/RELEASE_ARM64_T6000 arm64
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
            if (this.Resources.Configuration.HardKeyboardHidden == HardKeyboardHidden.No)
            {
                var window = ((Activity)currentcontext).Window;
                window.SetSoftInputMode(SoftInput.StateAlwaysHidden);
                if (Control != null)
                {
                    Control.ShowSoftInputOnFocus = false;
                }
            }
            else
            {
                var window = ((Activity)currentcontext).Window;
                window.SetSoftInputMode(SoftInput.StateVisible);
            }
        }
 void Button_Clicked(System.Object sender, System.EventArgs e)
        {
            entry.Focus();
        }
Screenshots
Workaround
I couldn't find any workaround
Please suggest me how to hide the soft keyboard while focusing the entry programmatically.
Please check in the latest available Xamarin.Forms version if this issue still persists, 2196 is a few versions back.
Hi @jfversluis In the latest version also I am facing the same issue
@jfversluis Can you please provide any suggestion on this?