如何在 TextInputLayout 上设置计数器的颜色?

How to set the color of the counter on a TextInputLayout?

我正在使用环绕 EditText 的 TextInputLayout。现在柜台是黑色的,我希望它是白色的。我不确定要设置什么选项才能让它变成白色。

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:counterEnabled="true"
        android:textColor="@color/white"
        android:textColorHint="@color/white"
        >

        <EditText
            android:id="@+id/myfield"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/white"
            android:hint="@string/myfield_hint"
            android:inputType="text"
            android:maxLength="26"
            android:textColor="@color/white"
            android:textColorHint="@color/white"/>
    </android.support.design.widget.TextInputLayout>

请补充:

app:counterTextAppearance="@android:color/white"

到您的 TextInputLayout。

希望对您有所帮助!

我决定根据上一篇的评论写下这个答案。

首先,您需要为您的计数器创建样式,例如:

<style name="CounterStyle" parent="TextAppearance.AppCompat.Small">
    <item name="android:textColor">@android:color/white</item>
    <!--other parameters that you want to change -->
</style>

然后将此样式添加到 TextInputLayout:

app:counterTextAppearance="@style/CounterStyle"

就是这样,它应该可以工作。完整代码:

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:counterEnabled="true"
        app:counterTextAppearance="@style/CounterStyle"
        android:textColor="@color/white"
        android:textColorHint="@color/white">

        <EditText
            android:id="@+id/myfield"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/white"
            android:hint="@string/myfield_hint"
            android:inputType="text"
            android:maxLength="26"
            android:textColor="@color/white"
            android:textColorHint="@color/white"/>
    </android.support.design.widget.TextInputLayout>

您还可以为溢出计数器使用一些样式:

app:counterOverflowTextAppearance="@style/YourOverflowTextStyleHere"

如所述here(感谢@Sufian link)