与Android密码字段问题,而不是躲在最后输入的字符躲在、字段、而不是、字符

2023-09-04 10:02:56 作者:一个爱笑的小仙女

在Android中,我创建了一个密码字段是这样的:

In Android, I create a password field like this:

    EditText text = new EditText(context);
    text.setTransformationMethod(PasswordTransformationMethod.getInstance());

还是这个样子,这似乎做同样的事情:

Or like this, which seems to do the same thing:

    EditText text = new EditText(context);
    text.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

我得到一个不错的密码字段除了由用户输入的最后一个字符。它的屏幕几秒钟就可见beeing掩盖了点之前。

I get a nice password field except for the last character typed by the user. It's visible on the screen for a few seconds before beeing masked with a dot.

下面是截图:

Here is a screenshot:

你知道如何解决这个问题吗?

Do you know how to fix this behaviour please?

推荐答案

这是预期的行为。随着大多数设备的软键盘,它是有价值的反馈,他们正在正确输入密码。

This is expected behavior. With the soft keyboards on most devices, it is valuable feedback that they are typing the password correctly.

有关所有不同inputTypes的列表,你可以指定,他们是如何改变的EditText,

For a list of all of the different inputTypes you can specify and how they change the EditText,

看机器人inputTypes 的。

另外,也可以通过执行来改变这种行为,你自己的 TransformationMethod 并通过 setTransformationMethod设置它() ,但我不建议这样做。用户会期望你所看到的,并通过改变你的应用程序,你会提供一个统一的用户体验的行为。

Also, it is possible to change this behavior by implementing your own TransformationMethod and setting it via setTransformationMethod(), but I would not recommend doing that. Users will expect the behavior you are seeing and by changing your app, you'll be providing an inconsistent user experience.

还检查该 Android的文章