当前位置: 首页 > 知识库问答 >
问题:

处于错误状态的TextInputLayout提示颜色

葛海阳
2023-03-14

根据Googles材料指南:

https://material.io/guidelines/components/text-fields.html#text-fields-layout

TextInputLayout提示应该与错误消息的颜色相同:

我如何更改此行为以适应Google自己的指导方针?

共有1个答案

全飞扬
2023-03-14

以下是如何做到这一点:

 <android.support.design.widget.TextInputLayout
        android:padding="8dp"
        android:id="@+id/tilSample"
        app:errorTextAppearance="@style/error_appearance"
        app:hintTextAppearance="@style/error_appearance"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/etSample"
            android:layout_margin="8dp"
            android:padding="8dp"
            android:hint="android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>

style.xml

<style name="error_appearance" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/colorRed</item>
        <item name="android:textSize">12sp</item>
    </style>

colors.xml

   <?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="colorRed">#f44336</color>
</resources>
tilSample.setErrorTextAppearance(R.style.error_appearance);  
tilSample.setHintTextAppearance(R.style.error_appearance);
 类似资料:
  • 就像外面的数百个问题一样,我想改变暗示的颜色。本来我想在评论中问另一个这样的问题(未回答),但我没有足够的声誉,所以我在这里问。 我希望当提示在TextInputEditText中时是一种颜色,当它浮动时是另一种颜色。在其他帖子中,答案总是在视图聚焦时如何更改提示。那不是我想要的,我能做到。如果编辑文本不是空的,我想更改提示颜色。我正在使用材料设计textInputLayout和TextInput

  • 我的需要是,为一个屏幕的应用程序,其中有白色的背景,并在白色的背景,我必须显示Textinputlayout提示,文本,编辑文本颜色在黑色字体。

  • 我正在使用设计库中新的。我能够让它显示和改变浮动标签的颜色。不幸的是,实际的提示现在总是白色的。 我尝试过用XML、样式和编程方式更改hintColor,还尝试过使用android。支持v7。小装置。AppCompatiEditText但是提示始终显示白色。 这是我的和 下面是我用于的样式(我尝试将属性设置为黑色,但没有为我做任何事情):

  • 我正在使用库。 正在调用,但没有显示错误。可能是什么问题?我怎么解决这个?