我以通常的方式实现了带有密码字段的textInputlayout:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/returning_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:inputType="textPassword"
android:maxLines="1"
android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>
使用Android支持库在版本24.0.2时效果很好,但是切换到25.0.1:
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:support-vector-drawable:25.0.1'
我不再看到小部件中的密码可见性切换(又称"眼图标")。更改为最新版本25.1.0没有解决此问题。
有什么我错过的,需要与支持库25结合使用,或者这是一个Android问题?
以这种方式尝试。
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/returning_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:inputType="textPassword"
android:maxLines="1"
android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>
这可能对您有帮助!
默认情况下,默认情况下禁用了TextInputlayout密码切换,以避免不必要地覆盖开发人员指定的最终绘制。它可以通过passwordToggleEnabled xml属性手动启用。
最近的支持库修订
如果使用喷气背包,则
添加这些依赖项
implementation 'com.google.android.material:material:1.0.0'
和add app:passwordToggleEnabled="true"
在xml中 还有一件事,请使用 inputType= textPassword
,如果您使用而不是使用此操作,则不会显示切换按钮。
而不是使用
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/returning_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:inputType="textPassword"
android:maxLines="1"
android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>
,您需要使用
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/returning_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:inputType="textPassword"
android:maxLines="1"
android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
您不需要添加以下内容:
app:passwordToggleEnabled="true"
只需将您的依赖性更改为:
compile 'com.android.support:design:25.0.0'
这是我更新依赖时遇到的错误。
编辑:
现在
app:passwordToggleEnabled="true"
正在使用
compile 'com.android.support:design:25.3.0'
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
应用:passwordToggleEnabled =" true">
<EditText
android:id="@+id/edt_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:maxLines="1"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
编译'com.android.support:design:25.0.1'
编译'com.android.support:support-v4:25.0.1'
编译'com.android.support:appcompat-v7:25.0.1'
编译'com.android.support:support-vector-drawable:25.0.1'