简体   繁体   English

如何以编程方式隐藏/禁用 Android 软键盘上的表情符号

[英]How to programmatically hide/disable emoticons on Android soft keyboard

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.我有一个EditText ,在某些设备上,它的键盘有笑脸,而在其他设备上却没有。 I want to hide it on all devices.我想在所有设备上隐藏它。

Below is the XML for my EditText :以下是我的EditText的 XML:

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"

Is this possible?这可能吗?

I found something in " Disabling smiley key on keyboards with the stock messaging app in ICS ".我在“ 使用 ICS 中的股票消息应用程序禁用键盘上的笑脸键”中找到了一些东西。

You need to remove the textLongMessage option from the inputType .您需要从inputType删除textLongMessage选项。

You will still have the ":-)" button on most keyboards, but not the emoji.大多数键盘上仍然会有“:-)”按钮,但不会有表情符号。

(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. @Adrian 的解决方案使用电子邮件地址类型,但它会在您的键盘上显示不必要的“@”和“.com”按钮。 I tried several combinations of InputType and the best solution IMHO is this:我尝试了几种 InputType 组合,恕我直言,最好的解决方案是:

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

Original Keyboard:原装键盘:

Resulting keyboard:结果键盘:

这在 Android 4.4.2 上对我有用

android:inputType="textEmailAddress|textMultiLine"

From Petr Daña in a similar question... This enables autocomplete and disables all the smileys.来自 Petr Daña 在一个类似的问题中......这将启用自动完成并禁用所有笑脸。

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 ".参考“ 如何在android中的EditText中检测表情符号”。

I tried @Adrian's solution, but it has "@" and ".com" keys.我尝试了@Adrian 的解决方案,但它有“@”和“.com”键。 I just need a field that can take user's name.我只需要一个可以取用户名的字段。 I got my solution by combining textVisiblePassword and textNoSuggestions :我通过结合textVisiblePasswordtextNoSuggestions得到了我的解决方案:

android:inputType="textVisiblePassword|textNoSuggestions

mEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD| TEXT_MULTILINE); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM