31

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"

Is this possible?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
ellen6a
  • 647
  • 2
  • 8
  • 11
  • 6
    No, as far as I know you cannot selectively hide keyboard buttons. Setting the inputType is all you can do but its up to the keyboard apps what they do with the inputType. – Xaver Kapeller May 09 '14 at 09:16

6 Answers6

14

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.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Scorpio
  • 1,124
  • 1
  • 11
  • 28
10

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

Niraj
  • 903
  • 8
  • 23
user1506104
  • 6,554
  • 4
  • 71
  • 89
1

This worked for me on Android 4.4.2

android:inputType="textEmailAddress|textMultiLine"
Adrian
  • 324
  • 2
  • 10
1

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".

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
dianakarenms
  • 2,609
  • 1
  • 22
  • 22
0

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"
Pranav Karnik
  • 3,318
  • 3
  • 35
  • 47
SajithK
  • 832
  • 10
  • 17
  • If a password manager is installed on the Android device it will show a pop on any field marked as "textVisiblePassword". I saw this on an Android 8 device and the app "Keypass2Android". – Peter F May 02 '19 at 14:33
-1

mEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD| TEXT_MULTILINE); 
Gladis Wilson
  • 8,400
  • 1
  • 12
  • 12
  • 3
    Please provide some context for this code snippet, and perhaps some explanation of why it improves on the other answers posted over the last 6 years. – miken32 Jan 20 '20 at 19:34
  • TYPE_TEXT_VARIATION_VISIBLE_PASSWORD - We use Password char as Text input for EditTest. It doesn't have emojis and email keys like .com and @ keys TEXT_MULTILINE - This will change the keyboard layout button [Done] or [->] to [Enter] key so we can use multi line text or new line feature. – Gladis Wilson Jan 21 '20 at 06:59