-
添加过滤器
mEtContent.setFilters(inputFilters);
-
实现过滤器
private InputFilter[] inputFilters=new 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); LogUtil.e("inputFilters : "+source+" dest: "+dest); if (emojiMatcher.find() ) { Toast.makeText(FeedBackActivity.this, "不支持输入表情", Toast.LENGTH_SHORT).show(); // MyToast.showText("不支持输入表情"); return ""; } return null; } }, new 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)); LogUtil.e("inputFilters2 : "+source+" type: "+type); if (type == Character.SURROGATE || type == Character.OTHER_SYMBOL) { Toast.makeText(FeedBackActivity.this, "不支持输入表情", Toast.LENGTH_SHORT).show(); return ""; } } return null; } }, /**这里限制输入的长度为200*/ new InputFilter.LengthFilter(200) };
OK