首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用数字时,将EditText imeOptions设置为actionNext不起作用

使用数字时,将EditText imeOptions设置为actionNext不起作用
EN

Stack Overflow用户
提问于 2017-07-27 20:57:00
回答 5查看 2.1K关注 0票数 10

这是我的编辑文本:

代码语言:javascript
复制
    <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现在已被弃用。我不能删除我的编辑文本中的数字,并且我不想使用过时的方法。任何人都可以解决这个问题。感谢您的支持

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2017-08-02 15:34:00

这是一个使用软件键盘按钮“下一步”的简化解决方案:

代码语言:javascript
复制
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的允许值。

票数 3
EN

Stack Overflow用户

发布于 2017-08-04 15:03:24

您可以使用

代码语言:javascript
复制
 android:lines="1"

代替

代码语言:javascript
复制
android:maxLines 

代码语言:javascript
复制
android:singleLine="true".

我知道您已经尝试了许多解决方案,请尝试

代码语言:javascript
复制
android:lines="1"

如果你之前没有尝试过的话。

票数 2
EN

Stack Overflow用户

发布于 2017-07-27 21:01:10

根据docsandroid:digits指定EditText具有数字输入法

您可以使用android:inputType="personName"实现与当前digits属性相同的效果

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45351481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档