Set inputType for an EditText Programmatically?


Question

How do we set the input type for an EditText programatically? I'm trying:

mEdit.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);

it doesn't seem to have any effect.

1
199
1/31/2019 3:23:46 PM

Accepted Answer

According to the TextView docs, the programmatic version of android:password is setTransformationMethod(), not setInputType(). So something like:

mEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());

should do the trick.

205
4/6/2010 8:37:25 PM

For setting the input type for an EditText programmatically, you have to specify that input class type is text.

editPass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon