InputMethodManager.ShowSoftInput is not launhing with Xamarin.5.0.0.2515

Venkata Subba Raju Ganapathiraju 21 Reputation points
2022-12-26T12:26:56.01+00:00

Our application with a feature to launch key board on tapping a button is working fine on Android platform with Xamarin.Forms.5.0.0.2244.
Post upgrade to 5.0.0.2515, keyboard is not launching.

Summary of Code

  1. View Model Contains code to show or HideKeybaord
    private readonly IKeyboardHelper keyboardHelper = DIController.GetService<IKeyboardHelper>();
    keyboardHelper.ShowKeyboard();
  2. ShowKeyboard implementation as
    Keyboard Helper is a class defined Android platform specific code as
    var ctx = Xamarin.Essentials.Platform.CurrentActivity;
    InputMethodManager inputMethodManager =
    (InputMethodManager)ctx.GetSystemService(Context.InputMethodService);
    inputMethodManager.ShowSoftInput(
    ctx.FindViewById(Android.Resource.Id.Content), ShowFlags.Forced);
Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-12-27T06:37:33.373+00:00

    Hello,

    You can use WindowInsetsControllerCompat to show or hide keyboard.

    Here is code about showing keyboard.

       var ctx = Xamarin.Essentials.Platform.CurrentActivity;  
         new WindowInsetsControllerCompat(ctx.Window, ctx.Window.DecorView).Show(WindowInsetsCompat.Type.Ime());  
    

    Here is code about hiding keyboard.

       var ctx = Xamarin.Essentials.Platform.CurrentActivity;  
         new WindowInsetsControllerCompat(ctx.Window, ctx.Window.DecorView).Hide(WindowInsetsCompat.Type.Ime());  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

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.