Xamarin PCL: Hide soft keyboard on android (Dependecy Service) doesn't work
<p>I trigger the code onfocus of an entry, but the hiding code in Android doesn't hide the soft keyboard.</p>

<h2>Interface</h2>

<pre><code>public interface IKeyboardService
{
    void Hide();
    void Show();
}
</code></pre>

<h2>ViewModel</h2>

<pre><code>public void OnFocused()
{
   var serv = DependencyService.Get&lt;IKeyboardService&gt;();

   if (cp.FindByName&lt;SwitchCell&gt;("SCell").On)
   {
      serv.Show();
   }
   else
   {
      serv.Hide();
   }
}
</code></pre>

<h2>Android Code</h2>

<pre><code>[assembly: Dependency(typeof(KeyboardService))]
namespace KeyboardHide.Droid.DependencyServices
{
    public class KeyboardService : IKeyboardService
    {
        public void Hide()
        {
            var inputMethodManager = Xamarin.Forms.Forms.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
            if (inputMethodManager != null &amp;&amp; Xamarin.Forms.Forms.Context is Activity)
            {
                var activity = Xamarin.Forms.Forms.Context as Activity;
                var focusedView = activity.CurrentFocus;
                var token = focusedView == null ? null : focusedView.WindowToken;
                inputMethodManager.HideSoftInputFromInputMethod(token, HideSoftInputFlags.None);
            }
        }

        public void Show()
        {

        }
    }
}
</code></pre>

<p>I also tried this code</p>

<h2>code</h2>

<pre><code>var inputMethodManager = Xamarin.Forms.Forms.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
if (inputMethodManager != null &amp;&amp; Xamarin.Forms.Forms.Context is Activity)
{
    var activity = Xamarin.Forms.Forms.Context as Activity;
    var focusedView = activity.CurrentFocus;
    var token = focusedView == null ? null : focusedView.WindowToken;
    inputMethodManager.ToggleSoftInputFromWindow(token, ShowSoftInputFlags.None, HideSoftInputFlags.None);
}
</code></pre>

<p>this worked for me by another project ??</p>

<p>*Edit:</p>

<p>Previous project (Works for another project of mine):</p>

<pre><code>var inputMethodManager = Xamarin.Forms.Forms.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
if (inputMethodManager != null &amp;&amp; Xamarin.Forms.Forms.Context is Activity)
{
    var activity = Xamarin.Forms.Forms.Context as Activity;
    var focusedView = activity.CurrentFocus;
    var token = focusedView == null ? null : focusedView.WindowToken;
    inputMethodManager.ToggleSoftInputFromWindow(token, ShowSoftInputFlags.None, HideSoftInputFlags.None);
}
</code></pre>

<p>But for my new project it doesn't work. I still see the keyboard, it doesn't hide it and I tried also:</p>

<pre><code>Device.BeginInvokeOnMainThread(() =&gt; serv.Hide());
</code></pre>