Hide Virtual keyboard when using InputField

后端 未结 1 626
粉色の甜心
粉色の甜心 2021-01-27 13:47

I know how to hide or display Virtual Keyboard using InputMethodManager.

But I want to enter text in EditText using Physical keyboard but I don

相关标签:
1条回答
  • 2021-01-27 14:27

    There is no such thing as EditText in Unity. InputField is used to receive input from a device.

    You can disable Virtual Keyword with InputField on Android. Not sure if this will work for other platforms.

    Your InputField:

    public InputField inputField;
    

    Disable Virtual Keyboard:

    inputField.keyboardType = (TouchScreenKeyboardType)(-1);
    

    Enable Virtual Keyboard:

    inputField.keyboardType = TouchScreenKeyboardType.Default;
    

    If you run into weird issues, consider deriving your script from InputField, then disable Virtual Keyboard and finally, call the base Start function of the InputField:

    public class HideVirtualKeyboard : InputField
    {
        protected override void Start()
        {
            keyboardType = (TouchScreenKeyboardType)(-1);
            base.Start();
        }
    }
    
    0 讨论(0)
提交回复
热议问题