美文网首页
Android 输入框(EditText)过滤 Emoji 表情

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

作者: 如沙雨下 | 来源:发表于2018-09-04 11:35 被阅读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()});

    相关文章

      网友评论

          本文标题:Android 输入框(EditText)过滤 Emoji 表情

          本文链接:https://www.haomeiwen.com/subject/klrgwftx.html