Android 输入框(EditText)过滤 Emoji 表情

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()});

你可能感兴趣的:(Android 输入框(EditText)过滤 Emoji 表情)