Tom Spee Tom Spee - 3 months ago 11x
Android Question

Xamarin C# EditText InputType Password

I got some EditText fields that are created from a Json file. So I can't change the XML files. But I want some EditText fields to have input type "password". I'm working in Xamarin Studio with C#.

I got something like this but that doesn't work, how can I fix this?

editText.InputType = InputTypes.TextVariationPassword;


Try this:

editText.InputType = Android.Text.InputTypes.TextVariationPassword | 

Edit: There are still some interest (i.e. votes) in this answer now after 2 years, so I thought of adding an explanation as requested by Bleeding Fingers in his comment below. I hope it will help somebody.

In many other languages/platforms (e.g. HTML), you just set your control to password and it works. That's what the OP was trying to do, but Android is designed differently (and quite odd IMHO). It divides the flags to classes and variations. You have to choose a class first (e.g. ClassText) and then apply the variations you want (e.g. TextVariationPassword). If you only set the variation, Android does not know what class you want. For instance, you can have a text password TextVariationPassword (so you combine it with the text class ClassText), or you can have a numeric password NumberVariationPassword (so you combine it with the number class ClassNumber).

Now all that explained starts to make some sense, except for a question somebody may ask: Can Android not simply infer the class from the variation so we don't have to specify redundant things? For the simple cases above it's pretty easy, but it gets more complex with several flags set to one control. Yet, I still personally think that it is relatively easily doable and better than the current redundant design that's taking many developers by surprise.