Keyboard keeps showing on Android emulator even when new page navigated to

Lloyd Sheen 1,486 Reputation points
2023-02-06T14:36:11.12+00:00

I have a search page. When I input into an Entry control and the lenght of the input is greater than 2 I query a service which gives me a list of things that partialy match the input. This list is then provided to a CollectionView to show. The problem is that the keyboard does not disappear as it did in Xamarin. To get rid of it on emulator I have to click the keyboard selection button and then select the keyboard and then it disappears.

Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Lloyd Sheen 1,486 Reputation points
    2023-02-21T13:41:02.53+00:00

    I had forgotten about this post. I found the following code which I use when the new page is navigated to, but still does not explain why Xamarin closes the keyboard and Maui does not:

        public void HideKeyboard()
        {
            var context = Android.App.Application.Context;
            var inputMethodManager = context.GetSystemService(Context.InputMethodService) as InputMethodManager;
            if (inputMethodManager != null)
            {
                var activity = Platform.CurrentActivity;
                var token = activity.CurrentFocus?.WindowToken;
                inputMethodManager.HideSoftInputFromWindow(token, HideSoftInputFlags.None);
                activity.Window.DecorView.ClearFocus();
            }
    
        }
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.