Android使用文本观察器来防止输入特殊字符
作者:互联网
参见英文答案 > How do I use InputFilter to limit characters in an EditText in Android? 16个
我想创建一个EditText框并使用TextWatcher来防止输入特殊字符.
解决方法:
这仅用于字符和空间验证…
InputFilter filter = new InputFilter()
{
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
for (int i = start; i < end; i++)
if (!Character.isLetter(source.charAt(i)) && !Character.isSpaceChar(source.charAt(i)))
return "";
return null;
}
};
myTextView.setFilters(new InputFilter[] { filter });
标签:android,textwatcher 来源: https://codeday.me/bug/20190530/1182724.html