Emoji 过滤

2017-11-18  本文已影响47人  詹徐照
// create InputFileter
private InputFilter mEmojiFilter = new InputFilter() {
        Pattern emoji = Pattern.compile(
                "[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",
                Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);

        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                                   int dend) {
            Matcher emojiMatcher = emoji.matcher(source);
            if (emojiMatcher.find()) {
                return "";
            }
            return null;
        }
    };

// setInputFilter
nameEt.setFilters(new InputFilter[]{mEmojiFilter});

参考:
http://www.pigg.co/emoji-filter.html

上一篇下一篇

猜你喜欢

热点阅读