美文网首页
Emoji 过滤

Emoji 过滤

作者: 詹徐照 | 来源:发表于2017-11-18 13:01 被阅读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

    相关文章

      网友评论

          本文标题:Emoji 过滤

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