使用数字将EditText imeOptions设置为actionNext无效 [英] Setting EditText imeOptions to actionNext has no effect when using digits

查看:397
本文介绍了使用数字将EditText imeOptions设置为actionNext无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的编辑文本:-

    <com.os.fastlap.util.customclass.EditTextPlayRegular
                    android:id="@+id/full_name_et"
                    style="@style/Edittext_white_13sp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/_5sdp"
                    android:background="#00ffffff"
                    android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
                    android:imeOptions="actionNext"
                    android:inputType="text"
                    android:maxLength="20"
                    android:maxLines="1"
                    android:nextFocusDown="@+id/last_name_et"
                    android:textCursorDrawable="@null" /> 

当我在edittext中删除digit时,它可以正常工作,但是使用digit imeOptions时,它不起作用.但是,如果我使用singleLine而不是maxLines,一件令人惊讶的事情就可以正常工作.但是现在不推荐使用singleLine. 我无法删除编辑文本中的数字,并且我不想使用不赞成使用的方法.任何人都可以解决这个问题.致谢

When I remove digit in edittext it work fine but with digit imeOptions doesn't work. But one surprising thing if I use singleLine instead of maxLines it work fine. But singleLine now is deprecated. I cannot remove digit in my edittext and I don't want use deprecated method. Any one can solve this problem. Thanks in adavance

推荐答案

以下是使用软件键盘按钮下一步"的简化解决方案:

Here is a simplified solution with the software keyboard button "Next":

final String NOT_ALLOWED_CHARS = "[^a-zA-Z0-9]+";

final EditText editText = (EditText) findViewById(R.id.editText);
editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

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

        @Override
        public void afterTextChanged(Editable s) {
            if (!TextUtils.isEmpty(s)) {
                // remove the listener to avoid StackoverflowException
                editText.removeTextChangedListener(this);
                // replace not allowed characters with empty strings
                editText.setText(s.toString().replaceAll(NOT_ALLOWED_CHARS, ""));
                // setting selection moves the cursor at the end of string
                editText.setSelection(editText.getText().length());
                // add the listener to keep watching
                editText.addTextChangedListener(this);
            }
        }
    });

在这里,正则表达式[^a-zA-Z0-9]+对应于所讨论的EditTextandroid:digits的允许值.

Here the regular expression [^a-zA-Z0-9]+ corresponds to the allowed values of android:digits of the EditText in question.

这篇关于使用数字将EditText imeOptions设置为actionNext无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆