Programmatically hide/disable emoticons on Android

2019-01-11 09:52发布

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 want to hide it on all devices.

Below is the XML for my EditText:

android:id="@+id/text_editor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/send_side"
android:hint="Enter your text"
android:imeOptions="actionSend|flagNoEnterAction"
android:inputType="textLongMessage|textAutoCorrect|textCapSentences|textMultiLine"
android:maxLength="1000"
android:maxLines="3"
android:nextFocusRight="@+id/send_button"
android:padding="12dp"
android:textSize="13sp"

I have to say I am new to Android and if this is not possible I would like to know why.

Thank you for your help.

4条回答
何必那么认真
2楼-- · 2019-01-11 10:23

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 the complete answer post

查看更多
聊天终结者
3楼-- · 2019-01-11 10:39

I don't really understand why the question is downvoted. It is a valid question.

I have found something here.

You need to remove the textLongMessage option from the inputType.

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

查看更多
在下西门庆
4楼-- · 2019-01-11 10:40

(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: enter image description here

Resulting keyboard: enter image description here

查看更多
Root(大扎)
5楼-- · 2019-01-11 10:41

This worked for me on Android 4.4.2

android:inputType="textEmailAddress|textMultiLine"
查看更多
登录 后发表回答