android EditText完美解决禁止输入法表情

给EditText设置过滤器

InputFilter[] emojiFilters = {emojiFilter};
sosMsg.setFilters(emojiFilters);
InputFilter emojiFilter = 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(getActivity(),"不支持输入表情", Toast.LENGTH_SHORT).show();
            return "";
        }
        return null;
    }
};
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐