On the soft keyboard in Android you can set the soft keyboard to show the numbers instead of a-z keyboard using android:inputType=\"numberDecimal\"
. However, wh
Last I looked into it, Android did not have any good options for that. I ended up having to write my own version of a soft keyboard-like user interface.
The accepted answer did not work for me (tested on OnePlus 3t and Samsung Galaxy S6/S7 phones).
This solution uses numberPassword but overrides the default transformation method for the EditText to show characters instead of showing dots.
<EditText
android:id="@+id/userid"
android:inputType="numberPassword"
android:maxLength="6"
/>
// Numeric 6 character user id
EditText input = findViewById(R.id.userid);
// Process input and show characters instead of dots
input.setTransformationMethod(SingleLineTransformationMethod.getInstance());
Just posted an answer here but re-posting for simplicity:
Seems Android has added the functionality we were seeking. This is the xml I use for simple EditText numeric entry:
android:inputType="numberPassword"
android:digits="0123456789"
android:singleLine="true"
android:ems="4"
android:textColor="@android:color/black"
android:gravity="center"
The accepted answer didn't work for me. It kept showing other unwanted characters
I found a way to accomplish the behavior I wanted by changing the inputType to numberPassword
and then disabling the password dots
textInput.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_PASSWORD
textInput.transformationMethod = SingleLineTransformationMethod()
You must only add this line on your code:
input.setRawInputType(Configuration.KEYBOARD_12KEY);
this will show only the numeric keyboard.
android:inputType="phone"
android:digits="1234567890"
is an option