为什么在TextInputLayout中找不到属性app:endIconMode?

aca*_*zas 10 android android-textinputlayout androidx

您好,我正在使用androidx库创建一个应用程序,但是当我尝试添加一个开关来显示或隐藏具有app:endIconMode属性的TextInputEditText中的密码时,出现错误错误:找不到属性endIconMode。

这是我的TextInputLayout和TextInputEditText

<com.google.android.material.textfield.TextInputLayout
            android:id="@+id/password_text_input_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="password"
            app:endIconMode="password_toggle"
            app:layout_constraintTop_toBottomOf="@+id/user_text_input_layout"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

        <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/password_text_input_edit_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"/>

    </com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

这些也是我在gradle中的依赖

implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'com.google.android.material:material:1.0.0'
Run Code Online (Sandbox Code Playgroud)

我不确定我缺少什么,也许是依赖关系?据我在文档中阅读的内容,除了材料之外,不需要任何额外的依赖。

谢谢

ian*_*ake 24

根据“ 材料设计组件”发行说明

1.1.0-alpha04

  • 添加对TextInputLayout的自定义结束图标的支持。(5685941

因此,您必须将依赖关系至少更改为1.1.0-alpha04,而不是1.0.0您正在使用的依赖关系:

implementation 'com.google.android.material:material:1.1.0-alpha04'
Run Code Online (Sandbox Code Playgroud)

  • 我知道我迟到了,但是在这个提交中实际上引入了对 `app:endIconMode` 属性的支持:https://github.com/material-components/material-components-android/commit/4c2e9c40040d1aa151f0534b21e3045dc2ccb788 (2认同)