这是我的编辑文本:
<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
现在已被弃用。我不能删除我的编辑文本中的数字,并且我不想使用过时的方法。任何人都可以解决这个问题。感谢您的支持
发布于 2017-08-02 15:34:00
这是一个使用软件键盘按钮“下一步”的简化解决方案:
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]+
对应于所讨论的EditText
的android:digits
的允许值。
发布于 2017-08-04 15:03:24
您可以使用
android:lines="1"
代替
android:maxLines
或
android:singleLine="true".
我知道您已经尝试了许多解决方案,请尝试
android:lines="1"
如果你之前没有尝试过的话。
发布于 2017-07-27 21:01:10
根据docs,android:digits
指定EditText具有数字输入法
您可以使用android:inputType="personName"
实现与当前digits
属性相同的效果
https://stackoverflow.com/questions/45351481
复制相似问题