editext does not support emoticons, but supports any content

Foreword: I read a lot of related content on the Internet. It did work. But punctuation marks cannot be typed. Some can play but can't completely mask the emoji. The following is the regular expression I found after a lot of testing,

        InputFilter inputFilter = new InputFilter() {
    
    
            Pattern pattern = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\ud83e\udc00-\ud83e\udfff]|[\u2600-\u27ff]",
                    Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);

            @Override
            public CharSequence filter(CharSequence charSequence, int i, int i1, Spanned spanned, int i2, int i3) {
    
    
                Matcher matcher = pattern.matcher(charSequence);
                if (!matcher.find()) {
    
    
                    return null;
                } else {
    
    
                    ToastUtils.showToast("只能输入汉字,英文,数字");
                    return "";
                }

            }
        };
        binding.editContent.setFilters(new InputFilter[]{
    
    inputFilter, new InputFilter.LengthFilter(300)});

Refer to the emoticon link emoticon connection,
I hope to help students in need

Guess you like

Origin blog.csdn.net/leol_2/article/details/106568449