Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable emojis programmatically in Android

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 suggestions:

txtSingupemail.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS 
                           |InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
txtSignuppwd.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_VARIATION_PASSWORD);
txtSignuppwd.setTransformationMethod(PasswordTransformationMethod.getInstance());

Here's the snapshot of my UI:

enter image description here

This is layout when user clicks signIn button. When user tap on bottom left icon which is marked red, the keyboard height goes increase due to emojis as suggestions.

See below snapshot:

enter image description here

Is there any way to hide those top emojis from keyboard programmatically?

like image 468
Ruchir Avatar asked Nov 30 '16 12:11

Ruchir


2 Answers

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;
        }
    }
like image 116
Anjali-Systematix Avatar answered Sep 17 '22 13:09

Anjali-Systematix


There are hundreds, if not thousands, of input method editors (a.k.a., soft keyboards) for Android.

None have to offer emoji. Those that do are welcome to offer them however they want, whenever they want.

There is no requirement for an input method editor to honor any flags that you put on the EditText. Therefore, there is no requirement for an input method editor to offer any means of blocking emoji input. And, even if some do offer this ability, others might not, and those that do might do so via different flags.

The decision of whether to have an emoji option on the keyboard is between the developers of the keyboard and the user (who chooses the keyboard to use). You do not get a vote.

Since AFAIK emoji are just Unicode characters, and since you should be supporting Unicode characters elsewhere (e.g., Chinese glyphs), it is unclear what technical reason you would have to avoid emoji. That being said, you are welcome to attempt to filter them out of the text being entered (e.g., use TextWatcher), if you are opposed to emoji.

like image 33
CommonsWare Avatar answered Sep 19 '22 13:09

CommonsWare