Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phone-like only numbers soft-keyboard

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?

like image 212
type-a1pha Avatar asked Aug 27 '12 22:08

type-a1pha


People also ask

How do I get my keyboard to only show numbers on Android?

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.

What is soft keyboard in Android?

The Android system shows an on-screen keyboard—known as a soft input method—when a text field in your UI receives focus.

How to show soft keyboard Android?

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.


1 Answers

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.

like image 84
zapl Avatar answered Nov 02 '22 20:11

zapl