How to programmatically hide/disable emoticons on Android soft keyboard

后端 未结 6 678
暗喜
暗喜 2020-12-03 01:25

Is it possible to hide a specific keyboard button? I have an EditText and on some devices its keyboard has smiley faces while on other devices it is missing. I

6条回答
  •  Happy的楠姐
    2020-12-03 01:36

    From Petr Daña in a similar question... This enables autocomplete and disables all the smileys.

    InputFilter filter = 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));
            //System.out.println("Type : " + type);
            if (type == Character.SURROGATE || type == Character.OTHER_SYMBOL) {
                return "";
            }
        }
        return null;
        }
    };
    
    mMessageEditText.setFilters(new InputFilter[]{filter});
    

    Refer to "How to detect emoticons in EditText in android".

提交回复
热议问题