How to disable emojis programmatically in Android

后端 未结 7 1083
走了就别回头了
走了就别回头了 2020-12-06 02:11

I want to hide emojis and auto suggestions from keyboard programmatically. Its working in some Android devices but not in all devices. here\'s my code for hide auto suggesti

7条回答
  •  忘掉有多难
    2020-12-06 02:45

    Try this it's works for me

    editText.setFilters(new InputFilter[]{new EmojiExcludeFilter()});
    private class EmojiExcludeFilter implements 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));
                    if (type == Character.SURROGATE || type == Character.OTHER_SYMBOL) {
                        return "";
                    }
                }
                return null;
            }
        }
    

提交回复
热议问题