要在EditText中设置启用的密码,我们必须在xml文件中设置“inputType”属性。如果我们只使用EditText,那么我们将在EditText中设置输入类型,如下面的代码所示。
<EditText
android:id="@+id/password_Edit"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLength="100"
android:nextFocusDown="@+id/next"
android:layout_width="match_parent"
android:layout_height="match_parent" />
密码启用属性是
android:inputType="textPassword"
但是,如果我们要实现与材料设计(设计支持库)密码的EditText那么我们将不得不写代码给出波纹管。
<android.support.design.widget.TextInputLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/txtInput_currentPassword"
android:layout_width="match_parent"
app:passwordToggleEnabled="false"
android:layout_height="wrap_content">
<EditText
android:id="@+id/password_Edit"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="@string/hint_currentpassword"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLength="100"
android:nextFocusDown="@+id/next"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.TextInputLayout>
@注意: - 在Android SDK 24及更高版本中,“passwordToggleEnabled”默认为true。因此,如果我们在密码EditText中有海关处理显示/隐藏功能,那么我们必须在代码中将其设置为false,如上所示。
app:passwordToggleEnabled="true"
要添加上面的行,我们必须在根布局中添加下面的行。
xmlns:app="http://schemas.android.com/apk/res-auto"
您的会员命名风格会给您带来麻烦。如果'Password'是一个真正存在的类,那么上帝会提防静态方法。 – 2011-05-23 09:02:44
我试过重命名..仍然没有运气 – Dhanesh 2011-05-23 09:25:14
我明白..非常感谢.. :) – Dhanesh 2011-05-23 09:35:31