Gowtham
Gowtham

Reputation: 13

How to hide softkeyboard in xamarin Android programmatically

This is my code to show keyboard:

AppData.SoftKeyBoard += () =>
        {
            InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
            imm.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
        };

I need a method to hide the softkeyboard.

Upvotes: 0

Views: 4416

Answers (2)

this code for hide soft keyboard in fragment of Xamarin Native Android:

View view = inflater.Inflate(Resource.Layout.fragment, container, false);
var imm =(InputMethodManager)Activity.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(view.WindowToken, 0);

and in Activity you can use this code:

InputMethodManager imm = (InputMethodManager)this.GetSystemService(Activity.InputMethodService);
//Find the currently focused view, so we can grab the correct window token from it.
View view = this.CurrentFocus;
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
    view = new View(this);
}
imm.HideSoftInputFromWindow(view.WindowToken, 0);

Upvotes: 1

Kyle
Kyle

Reputation: 1043

Here you go. This is code for Visual Studio.

// Hide keyboard
var inputManager = (InputMethodManager)GetSystemService(InputMethodService);
inputManager.HideSoftInputFromWindow(btnSignIn.WindowToken, HideSoftInputFlags.None);

Upvotes: 3

Related Questions