密码可见性在edittext中切换无法正常工作

时间:2016-12-27 08:50:15

标签: android-edittext android-design-library android-textinputlayout

当密码可见时,交叉眼睛图标不会出现。如何在眼睛图标上显示密码时放置十字标志。

<android.support.design.widget.TextInputLayout
                app:passwordToggleTint="@color/white"
                app:passwordToggleEnabled="true"
                android:textColorHint="#818893"
                android:layout_weight="0.4"
                android:layout_width="match_parent"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_height="match_parent"
                app:hintTextAppearance="@style/TextAppearance.AppCompat">

                <EditText
                    android:padding="10dp"
                    android:imeOptions="actionGo"
                    android:maxLines="1"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/password"
                    android:hint="Password"
                    android:inputType="textWebPassword" />
            </android.support.design.widget.TextInputLayout>

2 个答案:

答案 0 :(得分:2)

将支持库更新为25.1.0。在24.x

中存在密码切换可见性的一些已知问题

请参阅以下问题:

答案 1 :(得分:0)

试试此代码

<android.support.design.widget.TextInputLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="@dimen/login_linear_pwd_container_margin_top"
            android:background="@drawable/login_edittext_gradient"
            android:gravity="center"
            app:hintEnabled="false"
            app:passwordToggleDrawable="@drawable/password_visibility"
            app:passwordToggleEnabled="true">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/txtPassword"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@null"
                android:hint="@string/login_password_title"
                android:imeOptions="flagNoExtractUi"
                android:inputType="textPassword"
                android:paddingBottom="10dp"
                android:paddingLeft="@dimen/login_edittext_left_padding"
                android:paddingRight="@dimen/login_edittext_left_padding"
                android:paddingTop="10dp"
                android:textColor="@color/txt_black"
                android:textColorHint="@color/tab_text_color" />
        </android.support.design.widget.TextInputLayout>