How to programmatically hide/disable emoticons on Android soft keyboard

后端 未结 6 664
暗喜
暗喜 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条回答
  • 2020-12-03 01:31

    (For completeness sake)

    This solution is for people who need to have textview without the smiley on their soft keyboard. @Adrian's solution, to use email address type, works but it will show unnecessary '@' and '.com' buttons on your keyboard. I tried several combinations of InputType and the best solution IMHO is this:

    mTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
    

    Original Keyboard:

    Resulting keyboard:

    0 讨论(0)
  • 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".

    0 讨论(0)
  • 2020-12-03 01:38

    I found something in "Disabling smiley key on keyboards with the stock messaging app in ICS".

    You need to remove the textLongMessage option from the inputType.

    You will still have the ":-)" button on most keyboards, but not the emoji.

    0 讨论(0)
  • 2020-12-03 01:43

    I tried @Adrian's solution, but it has "@" and ".com" keys. I just need a field that can take user's name. I got my solution by combining textVisiblePassword and textNoSuggestions:

    android:inputType="textVisiblePassword|textNoSuggestions
    
    0 讨论(0)
  • 2020-12-03 01:45

    This worked for me on Android 4.4.2

    android:inputType="textEmailAddress|textMultiLine"
    
    0 讨论(0)
  • 2020-12-03 01:49
    
    mEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD| TEXT_MULTILINE); 
    
    0 讨论(0)
提交回复
热议问题