Search code examples
androidandroid-keypad

How do I default to numeric keyboard on EditText without forcing numeric input?


This has been asked elsewhere online to no avail. Is there any way in Android to display the numeric soft keyboard when focusing on an EditText, but still allow any text to be entered?

I'd like to let the user enter quantities (e.g. "1 kg", "2 L"), so just setting inputType="number" won't work.


Solution

  • Add the following line of code, and it will do the trick :)

    editText.setRawInputType(Configuration.KEYBOARD_QWERTY);

    This will show the the numeric keypad first, but also allows you to enter free text.

    More information here.