Skip to content Skip to sidebar Skip to footer

How To Force Number Keyboard When Inputtype Is Set To Numberpassword On Android

I was wondering how to configure an EditText element to show a number keyboard like the one shown when I specify its inputType as numberPassword. When masked, I have it set to mask

Solution 1:

Have you tried android:inputType="number"? The complete reference of available input types can be found here: https://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType

Solution 2:

You can either add android:inputType="Number" in edittext or set programatically as well:

final EditText input;
input.setInputType( InputType.TYPE_CLASS_NUMBER);

Solution 3:

Keep the same input type, but change the transformation method:

pw.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
checkBox.setOnCheckedChangeListener(newCompoundButton.OnCheckedChangeListener() {
  @OverridepublicvoidonCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {
      pw.setTransformationMethod(PasswordTransformationMethod.getInstance());
    }
    else {
      pw.setTransformationMethod(SingleLineTransformationMethod.getInstance());
    }
  }

Note that the same works for field of type InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD, but the keyboard will like

enter image description here

Post a Comment for "How To Force Number Keyboard When Inputtype Is Set To Numberpassword On Android"