隐藏Android默认键盘

本文关键字:键盘 默认 Android 隐藏 | 更新日期: 2023-09-27 18:03:34

我正在使用Xamarin和c#:

我用Keyboardview创建了一个自定义键盘,并希望禁用Android默认软键盘。

这个活动包含大约60行EditText。

这似乎不工作,它会出现一旦我点击另一个EditText。

Window.SetSoftInputMode (SoftInput.StateAlwaysHidden);
我KeyboardView

:

protected override void OnCreate (Bundle bundle){
  Window.SetSoftInputMode (SoftInput.StateAlwaysHidden);
  base.OnCreate (bundle);
  SetContentView (Resource.Layout.ORDER);
  mKeyboardView = this.FindViewById<KeyboardView> (Resource.Id.keyboardview);
  mKeyboardView.Keyboard = mKeyboard;
  mKeyboardView.PreviewEnabled = false;
  var keyboardListener = new MyKeyboardListener(this);
  mKeyboardView.OnKeyboardActionListener = keyboardListener;
}

隐藏Android默认键盘

您可以在单击时调用此方法,隐藏系统键盘,然后调用您的自定义键盘:

private void MakeEditable(bool isEditable, EditText et)
    {
        var imm = (InputMethodManager)GetSystemService(InputMethodService);
        if (isEditable)
        {
            et.Focusable = true;
            et.Enabled = true;
            et.Clickable = true;
            et.FocusableInTouchMode = true;
            et.SetSelection(et.Text.Length);
            et.RequestFocus();
            imm.ShowSoftInput(et, ShowFlags.Implicit);
        }
        else
        {
            et.Focusable = false;
            et.FocusableInTouchMode = false;
            et.Clickable = true;
            imm.HideSoftInputFromWindow(et.WindowToken, HideSoftInputFlags.None);
        }
    }