I'd like to have a phone-like soft-keyboard that allows to input ONLY numbers.
I can achieve the "only numbers" thing with inputType="number" (where the soft-keyboard is as default but allows only numbers as input) and the phone-like style with inputType="phone". But when put together like number|phone even if the style is the phone-like one, the soft-keyboard allows for symbols other than numbers.
I want the phone-like style since number buttons are BIGGER and easier to press and I only need to input numbers.
Any suggestions apart from creating a custom keyboard?
Using phone inputType EditText has an attribute called android:inputType . Providing android:inputType with value phone can display numbered keyboard when the EditText gets focus. Create an Android Project and replace layout (activity_main. xml) and Kotlin file (MainActivity.
The Android system shows an on-screen keyboard—known as a soft input method—when a text field in your UI receives focus.
By default, the soft keyboard may not appear on the emulator. If you want to test with the soft keyboard, be sure to open up the Android Virtual Device Manager ( Tools => Android => AVD Manager ) and uncheck "Enable Keyboard Input" for your emulator.
You can force the keyboard to the numeric one when you set the input type directly, not sure if that has extra buttons
EditText t = (EditText) findViewById(R.id.edittext1);
t.setRawInputType(Configuration.KEYBOARD_12KEY);
or
t.setRawInputType(InputType.TYPE_CLASS_PHONE);
I've used the first one quite some time ago and it worked, not sure about recent Android versions.
But, you can't influence the layout. They keyboard is provided by the current app that does the keyboard, it can do anything it wants. Even things like giving you 2 buttons to let the user input morse code like https://play.google.com/store/apps/details?id=org.emergent.android.morseime.
If that is keyboard you get is not what you want you have to implement your own - a relatively simple layout with 10 buttons is not that much work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With