首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TextInputLayout不会设置errorIconDrawable

TextInputLayout不会设置errorIconDrawable
EN

Stack Overflow用户
提问于 2020-08-14 04:18:03
回答 2查看 603关注 0票数 1

当我将style="@style/Widget.Design.TextInputLayout"用于TextInputLayout时,设置app:errorIconDrawable什么也不做。只有当我不设置样式并让它继承应用程序主题(Theme.MaterialComponents.Light.NoActionBar)时,它才能工作。app:endIconDrawable也不起作用,我无法找到替代/解决这个问题的方法。请帮帮我!

以下内容在继承应用程序主题时有效:Theme.MaterialComponents.Light.NoActionBar,但我不想使用这种样式,特别是下划线与文本不一致:

代码语言:javascript
复制
<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/login_password_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="username"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

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

</com.google.android.material.textfield.TextInputLayout>

这使用了我需要的样式,但不会显示错误图标:

代码语言:javascript
复制
<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/login_password_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="username"
    style="@style/Widget.Design.TextInputLayout"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

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

</com.google.android.material.textfield.TextInputLayout>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-14 08:01:33

由于您使用的是遗留样式Widget.Design.TextInputLayout,所以它不支持*.OutlinedBox*.FilledBox样式所具有的所有文本字段特性。

不能在xml中设置errorIconDrawable,必须在TextInputLayout.setError之后调用TextInputLayout.setErrorIconDrawable

代码语言:javascript
复制
login_password_input_layout.setError("Error text!!");                
login_password_input_layout.setErrorIconDrawable(R.drawable....);

票数 4
EN

Stack Overflow用户

发布于 2020-08-14 06:15:38

嗯,看看你是否直接在下面使用

style=“@style/Widget.Design.extInputLayout”

然后,您的错误可绘制变为空。

我建议您,创建一个样式,根据您的喜好修改这些值。

代码语言:javascript
复制
<style name="TextLabel" parent="Widget.Design.TextInputLayout">
    <item name="android:textColorHint">#f32</item>
    <item name="android:textSize">20sp</item>
    <item name="colorAccent">#4CAF50</item>
    <item name="errorIconDrawable">@drawable/ic_baseline_error_24</item>
    <item name="colorControlNormal">#673AB7</item>
    <item name="colorControlActivated">#E91E63</item>
    <item name="errorEnabled">true</item>
</style>

然后将其应用于via

代码语言:javascript
复制
   <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/login_password_input_layout"
        android:theme="@style/TextLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:hint="username"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

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

    </com.google.android.material.textfield.TextInputLayout>

这应该能解决。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63406480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档