Change the color of the floating text in a TextInputLayout

1

My goal is to change the color of the floating text when this field loses focus, I explain: I have a login screen, in which the background is red, so the goal is that the text is white to avoid losing, the problem is that when this field has text and loses focus, change to the primary color

Elements without focus:

In the first element I have already entered information and the focus is on the second widget, and the color change is appreciated.

XML element:

<android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="prueba"
                app:hintTextAppearance="@style/test_appearance">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:maxLines="1"
                    android:padding="8dp"
                    android:textColor="@color/color.black"
                    android:background="@color/color.white"/>
            </android.support.design.widget.TextInputLayout>

This is the style applied to the Widget:

<style name="test_appearance" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/color.white</item>
    <item name="android:textSize">14sp</item>
</style>
    
asked by dámazo 11.10.2017 в 18:17
source

2 answers

1

When the view loses focus, the "hint" is displayed so in your style you can add android:textColorHint :

 <item name="android:textColorHint">@color/<colo></item> 

and for other states, too:

<item name="colorAccent">@color/<colo></item>
<item name="colorControlNormal">@color/<colo></item>
<item name="colorControlActivated">@color/<colo></item>
    
answered by 11.10.2017 в 18:25
1

One way to do it is to use the following style in the AppTheme:

<item name="colorControlActivated">@color/TU_COLOR</item>

You tell me if it works for you.

    
answered by 11.10.2017 в 18:30