简体   繁体   English

Android EditText软键盘问题

[英]Android EditText soft keyboard question

I have EditText what should get user input for airplane seat number (like 17G, 5A etc) Problem is then I set EditText input type to text, it always open up soft keyboard with text. 我有EditText,应该从用户那里得到飞机座位号的输入(例如17G,5A等),然后问题是我将EditText输入类型设置为text,它总是用文本打开软键盘。 But my input always starts with numbers, so user have to switch keyboard to numbers and back all the time. 但是我的输入始终以数字开头,因此用户必须始终将键盘切换为数字并返回。 Question is how to setup keyboard to open text keyboard on part where numbers located? 问题是如何设置键盘以在数字所在的部分打开文本键盘? I try'd to put android:inputType="numeric" but it just open numeric keyboard and it is not possible to enter any text after. 我试着把android:inputType =“ numeric”放进去,但是它只是打开数字键盘,之后无法输入任何文本。

Since seat number (your example) will have different number count, it's kinda difficult guessing when to change from one keyboard type to another. 由于座位号(您的示例)将具有不同的号码计数,因此很难猜测何时从一种键盘类型更改为另一种键盘类型。

Otherwise, you can change EditText input type programmatically like this: 否则,您可以像下面这样以编程方式更改EditText输入类型:

((EditText) mView.findViewById(R.id.et_seat_number)).addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable editable) {

            EditText etSeatNumber = (EditText) mView.findViewById(R.id.et_seat_number);
            if(editable.length() > 2)
                etSeatNumber.setInputType(InputType.TYPE_CLASS_NUMBER);
            else{
                etSeatNumber.setInputType(InputType.TYPE_CLASS_TEXT);
            }
        }
    });

Also you can use softkeyboard IME options to change keyboard input type. 您也可以使用软键盘的IME选项更改键盘输入类型。 https://stackoverflow.com/a/40526750/6672482 https://stackoverflow.com/a/40526750/6672482

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM