java - 想要在我的 Android 应用程序中显示密码切换/可见按钮

标签 java android xml

我的 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/

相关文章:

java - 当有人点击保存按钮时显示一个弹出窗口(JDialog)

java - 寻找等待时间最短的路径

java - 将相对布局转换为位图并将其及其子元素保存到手机图库中

java - Android:为什么不推荐使用 SoundPool 的构造函数?

滚动时 Android ListView 样式问题与背景

android - ScrollView 在 Android 中不工作

xml - 在 Yii 中显示 XML 文档

java - 尝试运行 Google 语音识别 java 示例时出现 "need path to queries.json"错误

xml - 如何将复杂的 XML 解析为 R 中的长格式数据框

xml - XML 格式的 Euribor 利率