Jorge B. Jorge B. - 5 months ago 75
Android Question

EditText view with keyboard number only

I want a keyboard with ONLY visible numbers to an EditText view. Without any other character.

I have tested with all available inputs and don't work.
I have searched a way to get a keyboard only with numbers but I have only seen references to:

android: inputType = "numberPassword"


But I want visible numbers in EditText.
Someone can help me?

I want a keyboard like that: (numberPassword)

enter image description here

I have tried with:

android:digits="0123456789"
android:inputType="phone"


and

android:inputType="number"


and appears like that:

enter image description here

Answer

After several tries, I got it! I'm setting the keyboard values programmatically like that

 myEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); 

Or if you want you go with the XML view is like:

android: inputType = "numberPassword"

Both configs gonna display a password bullets, and as far as we are looking display numbers on the EditText we need to create a custom ClickableSpan class.

 private class NumericKeyBoardTransformationMethod extends PasswordTransformationMethod {
    @Override
    public CharSequence getTransformation(CharSequence source, View view) {
        return source;
    }
}

And finally we need implementing it to the EditText in order to display the characters typed.

myEditText.setTransformationMethod(new NumericKeyBoardTransformationMethod());

This is how my keyboard looks like now