我正在开发一个应用程序,我希望我的edittext应该仅使用Name。我尝试使用,android:inputType="textCapSentences"
但似乎无法正常工作。我的edittext仍在使用表情符号。
所以,有什么办法可以限制Android的编辑文本中输入的任何特殊字符或表情符号。如果有人有想法,请回复。提前致谢。
您可以使用表情符号过滤器作为下面的代码
mEditText.setFilters(new InputFilter[]{EMOJI_FILTER});
public static InputFilter EMOJI_FILTER = new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
boolean keepOriginal = true;
StringBuilder sb = new StringBuilder(end - start);
for (int index = start; index < end; index++) {
int type = Character.getType(source.charAt(index));
if (type == Character.SURROGATE || type == Character.OTHER_SYMBOL) {
return "";
}
char c = source.charAt(index);
if (isCharAllowed(c))
sb.append(c);
else
keepOriginal = false;
}
if (keepOriginal)
return null;
else {
if (source instanceof Spanned) {
SpannableString sp = new SpannableString(sb);
TextUtils.copySpansFrom((Spanned) source, start, sb.length(), null, sp, 0);
return sp;
} else {
return sb;
}
}
}
};
private static boolean isCharAllowed(char c) {
return Character.isLetterOrDigit(c) || Character.isSpaceChar(c);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句