Skip to content

Instantly share code, notes, and snippets.

@icalderond
Created June 20, 2016 22:30
Show Gist options
  • Save icalderond/742f98f2f8cda1fae1b0bc877df76bbc to your computer and use it in GitHub Desktop.
Save icalderond/742f98f2f8cda1fae1b0bc877df76bbc to your computer and use it in GitHub Desktop.
Hide and show keyboard android Xamarin
/**
* Hides the soft keyboard
*/
public void hideSoftKeyboard ()
{
var currentFocus = Activity.CurrentFocus;
if (currentFocus != null) {
InputMethodManager inputMethodManager = (InputMethodManager)Activity.GetSystemService (Context.InputMethodService);
inputMethodManager.HideSoftInputFromWindow (currentFocus.WindowToken, HideSoftInputFlags.None);
}
}
/**
* Shows the soft keyboard
*/
public void showSoftKeyboard (View view)
{
InputMethodManager inputMethodManager = (InputMethodManager)Activity.GetSystemService (Context.InputMethodService);
view.RequestFocus ();
inputMethodManager.ShowSoftInput (view, 0);
}
@gfmoore
Copy link

gfmoore commented Apr 27, 2022

Hi, fliipin eck it worked!!! :)

I'm new to Xamarin so had a lot of issues getting the keyboard to disappear, but your example I was able to use and hack.

One thing is that in VS 2022 I have had to use an [obsolete] directive on the showSoftKeyboard method. I think it was to do with the ToggleSoftInput method. Don't suppose you have any ideas on how to update that? But anyway thanks for posting this solution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment