EditText密码切换按钮未显示密码

时间:2018-03-24 12:16:13

标签: java android string android-edittext android-support-library

我正在使用支持库com.android.support:design:27.0.2,我在EditText

中实施了密码切换
 <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:textColorHint="@color/primary_dark"
            android:id="@+id/edit_inputPassword"
            app:passwordToggleEnabled="true"
            app:passwordToggleTint="@color/primary_dark"
            app:passwordToggleDrawable="@drawable/ic_remove_red_eye_black_24dp">
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Password"
                android:elevation="15dp"
                android:inputType="textPassword"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:id="@+id/edit_editPassword"/>
        </android.support.design.widget.TextInputLayout>

我在上面的代码后面得到了这个密码框 Toggle Password

但是当我点击Toggle按钮(Eye按钮)时,它没有显示密码String

1 个答案:

答案 0 :(得分:0)

考虑使用android.support.design.widget.TextInputEditText而不仅仅是EditText

<android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:textColorHint="@color/primary_dark"
            android:id="@+id/edit_inputPassword"
            app:passwordToggleEnabled="true"
            app:passwordToggleTint="@color/primary_dark"
            app:passwordToggleDrawable="@drawable/ic_remove_red_eye_black_24dp">
            <android.support.design.widget.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Password"
                android:elevation="15dp"
                android:inputType="textPassword"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:id="@+id/edit_editPassword"/>
        </android.support.design.widget.TextInputLayout>