我的 Android 应用程序有一个登录 Activity 。由于测试,我经常输入密码,有时我不确定密码是否正确,因此我需要将其完全删除并重新输入。我觉得这不是设计!我稍微搜索了一下,发现有一个名为 app:passwordToggleEnabled="true"
的函数。我试过了,但它抛出了一个错误。
我的代码:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:layout_marginTop="24dp"
android:id="@+id/loginPassword"
android:layout_below="@+id/loginEmail"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Passwort"
android:selectAllOnFocus="false"
android:textSize="18sp"
android:textColorLink="#63c3c3"
android:textColorHighlight="#63c3c3"
android:textCursorDrawable="@null"
android:backgroundTint="#63c3c3"
android:passwordToggleEnabled="true" //HERE!
android:cursorVisible="true" />
但是我得到一个错误..
Error:(14) No resource identifier found for attribute 'passwordToggleEnabled' in package 'android'
谢谢你帮助我:)
最佳答案
您需要 TextInputLayout 和 TextInputEditText
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleContentDescription="description"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/colorAccent">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
关于java - 想要在我的 Android 应用程序中显示密码切换/可见按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41643188/