在代码中添加:
editText.setFilters(new InputFilter[]{inputFilter, new InputFilter.LengthFilter(10)});//禁止输入表情以及限制输入长度为10
InputFilter inputFilter = 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()) {
Toast.makeText(context,"昵称不可以输入表情",Toast.LENGTH_SHORT).show();
return "";
}
return null;
}
};
更多好内容戳下面: