问题描述
这是我的编辑文本:-
<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]+
对应于所讨论的EditText
的android: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无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!