I just basically want to switch to the number pad mode as soon a certain EditText has the focus.
-
4The question does not specifically state a desire to change the allowed input type. It simply asks how to change the keyboard mode which is what I would like to do without changing the input type. All answers explain how to change the input type. – AlanKley Jun 09 '13 at 13:52
-
Check my answer on this question http://stackoverflow.com/questions/39593324/cannot-resolve-symbol-showsoftinput/39593871#39593871 – Android Help Sep 20 '16 at 12:22
13 Answers

- 74,165
- 16
- 97
- 99
-
6Also note that you need to target Android 1.5 to use this (it's not available in 1.1) – Wilka Aug 09 '09 at 19:47
-
4The problem is that you can't switch back. Using "number|text" does not work either. It seems if you want to show a numeric keyboard, you can't allow it switch back to text. – Aug 18 '11 at 20:18
-
I agree with Brian..if the first field is alpha and next field is numeric, I cannot go to the next field using the 'Next' button! – Ahmed Faisal Mar 21 '12 at 17:57
-
Whether you can go back or not depends on the phone I think. Mine allows it. – Martin Clemens Bloch Feb 24 '14 at 11:43
-
I want to change keybord type number and I want paste text in edittext. How to do? – ibyanik Nov 30 '18 at 06:29
To do it in a Java file:
EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_NUMBER);

- 1,141
- 1
- 7
- 2
I found this implementation useful, shows a better keyboard and limits input chars.
<EditText
android:inputType="phone"
android:digits="1234567890"
...
/>
Additionally, you could use android:maxLength
to limit the max amount of numbers.
To do this programmatically:
editText.setInputType(InputType.TYPE_CLASS_PHONE);
KeyListener keyListener = DigitsKeyListener.getInstance("1234567890");
editText.setKeyListener(keyListener);

- 1,315
- 12
- 12
-
Is there any way to do this programmatically? Dying to get a limited number keyboard for my EditText but it's set up in such a way it has to be generated in the activity. – Martin Erlic Dec 30 '15 at 02:54
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...
android:inputType="number|phone"/>
will show the large number pad as dialer.

- 3,769
- 6
- 30
- 49

- 23,891
- 30
- 115
- 165
You can do it 2 ways
Runtime set
EditText input = new EditText(this); input.setInputType(InputType.TYPE_CLASS_NUMBER);
Using XML
<EditText ... android:inputType="number" />

- 7,816
- 9
- 47
- 82

- 13,753
- 3
- 39
- 54
If you need fractional number, then this is the answer for you:
android:inputType="numberDecimal"

- 9,647
- 1
- 45
- 41
If you are using your EditText in Dialog or creating dynamically and You can't set it from xml then this example will help you in setting that type of key board while you are using dynamic Edit Text etc
myEditTxt.setInputType(InputType.TYPE_CLASS_NUMBER);
where myEditTxt is the dynamic EDIT TEXT object(name)

- 10,505
- 1
- 82
- 81
editText.setRawInputType(InputType.TYPE_CLASS_NUMBER);

- 1,168
- 12
- 17
-
If you are manually formatting a text (like for currency) and want to control just the keyboard, that's the choice. Won't filter your chars. Thanks! – lauksas Sep 29 '18 at 19:36
-
This worked like a charm for me. I want to display a textual placeholder value when a field has not been edited yet, but still restrict the input to numbers and display a restricted keyboard. – Alex Suzuki Sep 23 '19 at 15:27
Use the below code in java file
editText.setRawInputType(Configuration.KEYBOARD_QWERTY);

- 501
- 5
- 9
Below code will only allow numbers "0123456789”, even if you accidentally type other than "0123456789”, edit text will not accept.
EditText number1 = (EditText) layout.findViewById(R.id.edittext);
number1.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_CLASS_PHONE);
number1.setKeyListener(DigitsKeyListener.getInstance("0123456789”));

- 3,235
- 1
- 14
- 30
-
You should add commentary explaining your code and why it is the solution – cyroxis Nov 01 '18 at 14:49
EditText number1 = (EditText) layout.findViewById(R.id.edittext);
number1.setInputType(InputType.TYPE_CLASS_NUMBER);

- 3,770
- 2
- 30
- 25
-
If you have EditText number1 created in layout xml code, then if you want to set Number Keyboard to number1 EditText, you can do this way using Java Code. – Shiv Buyya Apr 23 '18 at 13:08