// 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
网友评论