Only show number buttons on Soft Keyboard in Android?

Viewed 55498

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, what do I do if I only want to show the top number row 1 2 3 4 5 6 7 8 9 0 and not the following rows starting with @ # $ % ...?

Thanx for listening!

9 Answers

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());

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()

From code:

et.setInputType(InputType.TYPE_CLASS_NUMBER)
Related