You need to create an Interface first.
public interface IKeyboardHelper
{
public void HideKeyboard();
}
Than you need to create related class in
Platforms> Android > Dependencies
Sample code
public class DroidKeyboardHelper : IKeyboardHelper
{
public DroidKeyboardHelper()
{
}
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();
}
}
}
The name space should have
[assembly: Dependency(typeof(DroidKeyboardHelper))]
Register at app.xaml.cs
DependencyService.Register<Platforms.Droid.Dependenices.DroidKeyboardHelper>();
Than on the calling location use
DependencyService.Get<IKeyboardHelper>().HideKeyboard();