Android 输入框(EditText)过滤 Emoji 表情
2018-09-04 本文已影响21人
如沙雨下
public class EmojiExcludeFilter implements InputFilter {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
int type = Character.getType(source.charAt(i));
if (type == Character.SURROGATE || type == Character.OTHER_SYMBOL) {
return "";
}
}
return null;
}
}
----调用----
mLoginPwdEt.setFilters(new InputFilter[]{new EmojiExcludeFilter()});