概述 TextInputLayout 中带有提示的错误

Posted

技术标签:

【中文标题】概述 TextInputLayout 中带有提示的错误【英文标题】:Bug with hint in outlined TextInputLayout 【发布时间】:2021-12-16 09:00:24 【问题描述】:

我遇到了一个恼人的错误:当我将角半径设置为大于 8dp 时,焦点状态中的提示与笔划重叠(textInputLayout 的边框)。我试图为editTextView设置填充,但它没有帮助我。有什么解决办法吗?

错误:

布局:

<com.google.android.material.textfield.TextInputLayout
            android:id="@+id/global_search_ti_container"
            style="@style/TextInputLayoutStyle"
            android:layout_
            android:layout_
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:startIconDrawable="@drawable/ic_search_24dp">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/global_search_ti_text"
                android:layout_
                android:layout_
                android:clickable="true"
                android:focusable="true"
                android:fontFamily="@font/roboto"
                android:hint="@string/search_by_people"
                android:maxLength="100"
                android:singleLine="true"
                android:textColor="@color/soft_white"
                android:textColorHint="@color/soft_red"
                android:textCursorDrawable="@drawable/cursor_color"
                android:textSize="14sp" />
        </com.google.android.material.textfield.TextInputLayout>

样式:

<style name="TextInputLayoutStyle"
        parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
        <item name="android:layout_margin">16dp</item>
        <item name="boxCornerRadiusBottomEnd">30dp</item>
        <item name="boxCornerRadiusBottomStart">30dp</item>
        <item name="boxCornerRadiusTopStart">30dp</item>
        <item name="boxCornerRadiusTopEnd">30dp</item>
        <item name="startIconTint">@color/soft_red</item>
        <item name="boxStrokeColor">@color/text_input_stroke_color</item>
        <item name="boxStrokeWidth">1.5dp</item>
        <item name="errorEnabled">true</item>
        <item name="android:textColorHint">@color/text_input_hint</item>
        <item name="hintTextColor">@color/soft_red</item>
    </style>

【问题讨论】:

【参考方案1】:

看起来像这个问题:https://github.com/material-components/material-components-android/issues/2145

根据this commit,问题应该在 1.5.0-alpha05 中得到解决。请检查它在指定版本的库上是如何工作的

【讨论】:

是的,它解决了我的问题。发布版本中存在相当烦人的错误..

以上是关于概述 TextInputLayout 中带有提示的错误的主要内容,如果未能解决你的问题,请参考以下文章

更改 TextInputLayout 仅提示文本样式

更改 TextInputLayout 提示行为

TextInputLayout使用时各个地方的字体颜色

提示在 TextInputLayout 中的位置太高

使用 TextInputLayout 时更改 EditText 提示颜色

以编程方式更改TextInputLayout提示颜色