简体   繁体   中英

How to change default color of Android Floating Label for TextInputLayout?

I am able to change the color of a floating label for a TextInputLayout that is wrapping an EditText. When it floats up during the animation phase using the below code I am able to select the color black (default is white) using "android:textColor". I am trying to select a different color when the EditText becomes unfocused--meaning when the floated label becomes permanent above the EditText. My minimum API is 14. Please advise.

partial themes.xml file:

<?xml version="1.0" encoding="utf-8"?>

<style name="AppTheme" parent="AppTheme.Base"/>

<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar" >
...
</style>

<style name="FloatingLabel" parent="@android:style/TextAppearance" >
    <item name="android:textColor">#000000</item>
</style>

partial layout.xml file:

...
<android.support.design.widget.TextInputLayout
    android:id="@+id/ToDo_text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:hintTextAppearance="@style/FloatingLabel"
    >
...

Add this in styles:

<style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/red</item>
    <item name="android:textSize">14sp</item>
</style>

Add this in your layout:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColorHint="@color/gray"
   **app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"**>

    <android.support.v7.widget.AppCompatEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hint" />
</android.support.design.widget.TextInputLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM