Search code examples
androidandroid-widgetuser-inputandroid-edittextandroid-softkeyboard

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?


Solution

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