Ana*_*ain 8 regex android android-edittext
这是我的edittext: -
<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" />
Run Code Online (Sandbox Code Playgroud)
当我digit在edittext中删除它工作正常,但digit imeOptions没有工作.但令人惊讶的是,如果我使用singleLine而不是maxLines,它可以正常工作.但singleLine现在已被弃用. 我无法删除编辑文本中的数字,我不想使用弃用的方法.任何人都可以解决这个问题.谢谢,谢谢
这是使用软件键盘按钮“下一步”的简化解决方案:
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);
}
}
});
Run Code Online (Sandbox Code Playgroud)
这里的正则表达式对应于所讨论[^a-zA-Z0-9]+的允许值。android:digitsEditText