简体   繁体   中英

keyboard change

I'd like to know if there's a possibility to change keyboard type after a certain number of characters (eg. XYZ123 - the keyboard should change to numeric after Z). Sorry if this is a re-post but I couldn't find anything like this.

You should use addTextChangedListener for this eg,

 yourEditText.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(String string, int i, int i1, int i2) {}

                @Override
                public void onTextChanged(String string, int i, int i1, int i2) {

                     if(string.contains("Z")){

                        yourEditText.setInputType(InputType.TYPE_CLASS_NUMBER);

                     }
                }

                @Override
                public void afterTextChanged(Editable editable) {}
            });

您可以做的是创建两种不同的布局,一种用于数字,一种用于纯文本,反之亦然,据我所知,除非将“光标”移动到X 字符后的下一个布局

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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