本文介绍了Xamarin EditText InputType密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些从JSON文件创建的EditText字段,所以我无法更改XML文件.但是我希望某些EditText字段具有输入类型"password".我正在使用C#在Xamarin Studio中工作.

I got some EditText fields that are created from a JSON file, so I cannot 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:

editText.InputType = InputTypes.TextVariationPassword;

推荐答案

尝试一下:

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

2年后,现在对该答案仍有一些兴趣(即票数),因此我想根据流血的手指的要求在他的回答中添加一个解释.在下面发表评论.我希望它能对某人有所帮助.

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.

在许多其他语言/平台(例如HTML)中,只需将控件设置为password即可.这就是OP想要做的,但是Android的设计有所不同(而且很奇怪,恕我直言).它将标志划分为变体.您必须先选择一个类别(例如ClassText),然后应用所需的变体形式(例如TextVariationPassword).如果您仅设置变体,Android将不知道您想要什么类.例如,您可以具有文本密码TextVariationPassword(因此可以将其与文本类ClassText结合使用),也可以具有数字密码NumberVariationPassword(因此可以将其与数字类ClassNumber结合使用).

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

现在,所有解释都开始变得有意义,除了有人可能会问的一个问题: Android不能简单地从变化中推断出类,这样我们就不必指定多余的东西了吗?上面的简单情况非常简单,但是通过将多个标志设置到一个控件,它会变得更加复杂.但是,我个人仍然认为,相对于目前使许多开发人员感到惊讶的冗余设计而言,它相对容易实现并且更好.

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.

这篇关于Xamarin EditText InputType密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 21:01