I am trying to get away from creating a custom keyboard. I was wondering if there was a way to hide a key in the default Android Soft Keyboard. For example, I have an EditText field that requires unsigned decimal numbers. But whenever the keyboard pops up, the "-" sign always shows and obviously, it is disabled. I would like to get rid of this "-" sign.
5 Answers
I was wondering if there was a way to hide a key in the default Android Soft Keyboard
No.
First, there is no single "default Android Soft Keyboard". Android ships on well over one billion devices, across thousands of models, with dozens of "default" keyboards installed. Users can also install soft keyboards as third-party apps.
Second, you have no ability to control any of them. At best, you can offer suggestions for what you want, using attributes like android:inputType
. However, those are requests, not commands, and the author of an input method editor does not have to honor them. Moreover, how they honor them is up to the author of the input method editor.
I am trying to get away from creating a custom keyboard.
That would be useless. You cannot force the user to use your keyboard. Your keyboard may not meet other requirements of the user. And so on.
For example, I have an EditText field that requires unsigned decimal numbers. But whenever the keyboard pops up, the "-" sign always shows and obviously, it is disabled. I would like to get rid of this "-" sign.
That is up to the implementer of the input method editor, not you. Some keyboards might hide the key. Some might disable the key. Some might ignore the signed/unsigned request entirely and just show a standard numeric keyboard. Some might ignore the numeric request entirely and show their standard keyboard, particularly if they do not really have the notion of "keys".

- 986,068
- 189
- 2,389
- 2,491
-
I should have mentioned that this app will be distributed in a closed environment, (as in Kiosk mode). We will have full control over the devices that this app will be installed in (since we will be providing the devices). So your concern over "default Android Soft Keyboard" will be irrelevant. For other applications not distributed in a controlled environment, your comment is spot on. – Arlyn May 06 '15 at 18:19
-
@KarimArlyn: "I should have mentioned that this app will be distributed in a closed environment" -- that's not a small item to miss. :-) In that case, your to-be-avoided option of writing your own IME is your only choice, and in your IME, you can do what you want. – CommonsWare May 06 '15 at 18:22
As an update, I conceded over just going with a custom keyboard. Since the keyboard I wanted is just numeric pad with a decimal point, and control keys such as delete, clear and Enter, it was easy to make.
I fashioned the keypad using the following tutorial (without the Hex and other special keys): http://www.fampennings.nl/maarten/android/09keyboard/index.htm
This tutorial had a flaw where the layout would not pan over for the keyboard. As a result, the EditText fields would hide under the keyboard. So I changed the CustomKeyboard class into an InputMethodService. To do this, I followed this tutorial
And finally, every time I edited an EditText, the whole screen would be hidden in landscape mode, because my app was only going to use landscape. So this was unacceptable. I found out I had to add this method in my CustomKeyboard class (since it is a derivative of InputMethodService) from this answer
Thank you all for helping me out. I hope this will help someone who is looking to do something similar.
Yes, you can Create a Custom Keyboard on Android.
Include this keyboard with your installed app and trigger your keyboard for the particular input boxes you are using.
See also: InputMethodService for APIs for binding and using input mechanisms.

- 613
- 5
- 8
Acording docs you can configure youe EditText
with using InputType
. Pay attention on TYPE_NUMBER_FLAG_SIGNED
Flag of TYPE_CLASS_NUMBER: the number is signed, allowing a positive or negative sign at the start.

- 3,470
- 4
- 44
- 84
I don't think it's possible without creating a custom keyboard. The default keyboard is typically implemented by the device manufacturer. Which is a reason why the xml property android:inputType
has varying effects across different devices.

- 712
- 7
- 20