【问题标题】:endIconTint in TextInputLayout is not workingTextInputLayout 中的 endIconTint 不起作用
【发布时间】:2021-06-23 07:56:52
【问题描述】:

我正在使用TextInputLayoutTextInputEditText 创建一个登录表单,但无论我将哪种颜色指定为endIconTint,切换密码图标始终显示为白色。我已经对此进行了测试

安卓 6
安卓 10

两者都显示相同的结果。

这是我在 TextInputLayout 中使用 Widget.MaterialComponents.TextInputLayout.OutlinedBox 作为样式时的表单。似乎它没有显示可绘制,但事实并非如此,因为它不可见,因为可绘制并且输入字段背景颜色为白色。当我单击末尾时,它会切换密码。

这是我使用Widget.MaterialComponents.TextInputLayout.FilledBox时的表单

这是我的代码,您可以看到我目前正在为 endIconTint 分配黑色

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/password_til"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:hint="Password"
        app:counterEnabled="true"
        app:counterMaxLength="20"
        app:endIconMode="password_toggle"
        app:endIconTint="@color/black"
        app:helperText="required*"
        app:helperTextTextColor="@android:color/holo_red_dark"
        app:layout_constraintTop_toBottomOf="@id/username_til"
        app:passwordToggleEnabled="true"
        app:startIconDrawable="@drawable/ic_key">

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

我从color.xml 文件中交叉验证了颜色并尝试了其他颜色,但图标始终显示为白色。请让我知道这里出了什么问题还是错误?

感谢和问候

【问题讨论】:

    标签: android input material-ui android-textinputlayout


    【解决方案1】:

    您已经指定了app:endIconMode="password_toggle",因此您不再需要设置passwordToggleEnabled

    TextInputLayout 中删除它,它可以解决您的问题。

    app:passwordToggleEnabled="true"

    【讨论】:

    • 哦,我的错,我之前添加了这个,忘记删除了。谢谢
    • 干杯!! @InzimamTariqIT
    猜你喜欢
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 2019-06-02
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多