android:inputType=“textPassword"、“textVisiblePassword&q

时间:2023-02-25
本文介绍了android:inputType=“textPassword"、“textVisiblePassword"、“textWebPassword"之间的区别和“数字密码"在安卓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

谁能解释一下两者的区别

Can anyone explain the differences between the

   android:inputType="textPassword",
   android:inputType="textVisiblePassword",
   android:inputType="textWebPassword",
   android:inputType="numberPassword"

Android Layout 中的 EditText ViewGroup?

of EditText ViewGroup in Android Layout?

推荐答案

即使已经回答了,我还是会在密码差异方面添加更多细节InputType 变体:

Even though it has been already answered I'll add some more details to the differences in password InputType variations:

  1. android:inputType="textPassword":对应TYPE_CLASS_TEXT |TYPE_TEXT_VARIATION_PASSWORD 即它允许您输入一个作为密码的字符串(隐藏并防止自动完成和建议,除非明确设置).这个主要用于我们要输入密码的时候.
  2. android:inputType="textVisiblePassword":对应TYPE_CLASS_TEXT |TYPE_TEXT_VARIATION_VISIBLE_PASSWORD 并且与前一个相同,但密码是可见的(如果您想使用它来允许查看默认密码,因为它会阻止自动完成和建议,除非它们被明确设置 - 这是可取的也有办法隐藏密码)
  3. android:inputType="numberPassword":对应TYPE_CLASS_NUMBER |TYPE_NUMBER_VARIATION_PASSWORDandroid:inputType="textPassword" 相同,但您只能输入数字.考虑到如果你使用它,密码不会那么强,所以我不建议在处理敏感数据时使用它,除非它与其他类型的用户身份验证一起使用.
  4. android:inputType="textWebPassword":对应TYPE_CLASS_TEXT |TYPE_TEXT_VARIATION_WEB_PASSWORD 并具有与 android:inputType="textPassword" 相同的行为,但它旨在用于 Web 表单,即在浏览器页面内(任何从用户).所以这不应在 EditText 本机控件中使用.使用此方法的示例是通过包装 WebView在 WebView 中禁用 Android 的 AutoSuggestion并更改 EditorInfo 输入类型以在 onCreateInputConnection 方法中添加标志 InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD.
  1. android:inputType="textPassword": Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD i.e. it allows you to enter a string that is taken as a password (hidden and preventing autocompletion and suggestions unless set explicitly). This one is mostly used when we want to enter passwords.
  2. android:inputType="textVisiblePassword": Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD and is the same as the previous one but the password is visible (useful if you want to use it to allow to see the password as default because it prevents the autocompletion and suggestions unless they are set explicitly - it is advisable to also have a way to hide the password)
  3. android:inputType="numberPassword": Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD same as android:inputType="textPassword" but you can only enter numbers. Take into account that if you use it the password will not be so strong, so I wouldn't recommend using it when dealing with sensitive data unless it is used along with another type of user authentication.
  4. android:inputType="textWebPassword": Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_PASSWORD and has the same behaviour as android:inputType="textPassword" but it is intended to be used in a web form i.e. inside a browser page (any web form control that takes input from a user). So this shall not be used in an EditText native control. An example of using this would be to disable AutoSuggestion from Android in a WebView by wrapping a WebView and changing EditorInfo input type to add the flag InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD inside the onCreateInputConnectionmethod.

作为从链接中截取的最后一个示例:

As an example of the last one taken from the link:

public class NoSuggestionsWebView extends WebView {
    ...

    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs)
    {
        InputConnection ic = super.onCreateInputConnection(outAttrs);

        outAttrs.inputType &= ~EditorInfo.TYPE_MASK_VARIATION; /* clear VARIATION type to be able to set new value */
        outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD; /* WEB_PASSWORD type will prevent form suggestions */

        return ic;
    }
}

我希望现在很清楚区别,主要是 android:inputType="textPassword"android:inputType="textWebPassword"

I hope it is clear now the differences and mainly between android:inputType="textPassword" and android:inputType="textWebPassword"

这篇关于android:inputType=“textPassword"、“textVisiblePassword"、“textWebPassword"之间的区别和“数字密码"在安卓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 EditText 中仅允许基于正则表达式的选定字符 下一篇:Listview android中的Edittext

相关文章

最新文章