You try this. First create interface in your shared project
public interface IKeyboardHelper
{
void HideKeyboard();
}
Implemented that in iOS project by adding new iOSKeyboardHelper.cs file
public class iOSKeyboardHelper : IKeyboardHelper
{
public void HideKeyboard()
{
UIApplication.SharedApplication.KeyWindow.EndEditing(true);
}
}
Now implement the same in your android project by adding new file DroidKeyboardHelper.cs
public class DroidKeyboardHelper : IKeyboardHelper
{
public void HideKeyboard()
{
var context = Forms.Context;
var inputMethodManager = context.GetSystemService(Context.InputMethodService) as InputMethodManager;
if (inputMethodManager != null && context is Activity)
{
var activity = context as Activity;
var token = activity.CurrentFocus?.WindowToken;
inputMethodManager.HideSoftInputFromWindow(token, HideSoftInputFlags.None);
activity.Window.DecorView.ClearFocus();
}
}
}
Call your method in shared project like this, Wherever you need it.
DependencyService.Get<IKeyboardHelper>().HideKeyboard()
visit this & this for more information.