Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using a TextInputLayout wrapped around an EditText. Right now the counter is black, I'd like it to be white. I'm not sure what option to set to get it to be white.

    <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>
like image 538
Andy Avatar asked Nov 23 '15 21:11

Andy


2 Answers

I decided to write this answer based on comments from previous one.

At first, you need to create the style for your counter, for example:

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

Then add this style to TextInputLayout:

app:counterTextAppearance="@style/CounterStyle"

That's all, it should works. Full code:

<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>

You can also use some style for the overflow counter:

app:counterOverflowTextAppearance="@style/YourOverflowTextStyleHere"

As described here (thanks @Sufian for the link)

like image 163
Evgen Avatar answered Sep 28 '22 07:09

Evgen


Please add:

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

to your TextInputLayout.

Hope this helps!

like image 35
Actiwitty Avatar answered Sep 28 '22 08:09

Actiwitty