title: Disable Soft Keyboard on Xamarin Forms
body: <p>I need to disable the soft keyboard on xamarin forms for custom entry. Ive searched for some solutions, tried some suggestions i found, but the keyboard still shows when customentry gets focus. If i tap on the control, keyboard doesnt showing, but if i make .Focus() in code, it appears. Heres some code i have, and what i tried to do:
  in XAML:</p>
  <pre><code>&lt;cutom:tb1 x:Name=&quot;tb1&quot; Grid.Column=&quot;2&quot;/&gt;
  </code></pre>
  <p>then the customentry:</p>
  <pre><code>public class tb1 : Entry
  {
  }
  </code></pre>
  <p>the android custom renderer, with the codes i tried:</p>
  <pre><code>[assembly: ExportRenderer(typeof(tb1), typeof(tb1Renderer))]
  </code></pre>
  <p>namespace whatever.Droid
  {
  class tb1Renderer : EntryRenderer
  {
  public tb1Renderer(Context context) : base(context)
  {
  }</p>
  <pre><code>    public override bool OnCheckIsTextEditor()
      {
          return false;
      }
  
      protected override void OnElementChanged(ElementChangedEventArgs&lt;Entry&gt; e)
      {
          base.OnElementChanged(e);
  
          if (Control != null)
          {
              Control.InputType = Android.Text.InputTypes.Null;
          }
  
          // Disable the Keyboard on Focus
          if (e.NewElement != null)
          {
              ((tb1)e.NewElement).PropertyChanging += DisableKeyboard;
          }
  
          if (e.OldElement != null)
          {
              ((tb1)e.OldElement).PropertyChanging -= DisableKeyboard;
          }
  
          this.Control.ShowSoftInputOnFocus = false;
          if ((e.OldElement == null) &amp;&amp; (Control != null))
          {
              HideKeyboard();
          }
      }
  
      private void DisableKeyboard(object sender, PropertyChangingEventArgs propertyChangingEventArgs)
      {
          // Check if the view is about to get Focus
          if (propertyChangingEventArgs.PropertyName == VisualElement.IsFocusedProperty.PropertyName)
          {
              // incase if the focus was moved from another Entry
              // Forcefully dismiss the Keyboard 
              InputMethodManager imm = (InputMethodManager)this.Context.GetSystemService(Context.InputMethodService);
              imm.HideSoftInputFromWindow(this.Control.WindowToken, 0);
          }
      }
  
      public void HideKeyboard()
      {
          Control.RequestFocus();
          var inputMethodManager = Control.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
          inputMethodManager.HideSoftInputFromWindow(this.Control.WindowToken, HideSoftInputFlags.None);
      }
  
  }
  </code></pre>
  <p>}</p>
  <p>tryed to turn that off in MainActivity.cs aswell</p>
  <pre><code>[Activity(WindowSoftInputMode = Android.Views.SoftInput.StateAlwaysHidden, ...
  </code></pre>
  <p>again, the keyboard does not show if i tap on entry, but when i make a button and a click event, the keyboard still shows</p>
  <pre><code>private async void btn1_Clicked(object sender, EventArgs e)
      {
          try { //await work to do }
          catch(Exception ex) { //some logging }
          finally { tb1.Focus(); }
      }
  </code></pre>