TextInputLayout - 在静止状态下更改EditText中的浮动标签提示颜色

cha*_*thu 3 android android-layout android-edittext android-textinputlayout

我正在使用TextInputLayout和浮动标签提示.但在正常状态下,我无法将提示颜色从白色更改为其他颜色.有没有办法做到这一点 ?

<android.support.design.widget.TextInputLayout
    android:id="@+id/fullNameTextLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:layout_weight="0.75">
    <EditText
        android:id="@+id/etFullName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dp"
        android:layout_marginLeft="15dp"
        android:layout_marginEnd="15dp"
        android:layout_marginRight="15dp"
        android:singleLine="true"
        android:hint="Full Name"
        android:textColor="@color/gray_dark"
        android:textColorHint="@color/green"
        android:textColorHighlight="@color/green" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

在背景改变的情况下附加两个屏幕截图.

同样看法有绿色背景

同样看法有白色背景

And*_*eam 6

请在TextInputLayout中添加,

  app:hintTextAppearance="@style/mytext 
Run Code Online (Sandbox Code Playgroud)

所以你的布局将是:

 <android.support.design.widget.TextInputLayout
        android:id="@+id/aeal_input_layout_zipcode"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColorHint="@color/green"
        app:hintTextAppearance="@style/mytext">
    <EditText
        android:id="@+id/aeal_etZipCode"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Zipcode"
        android:singleLine="true"
        android:inputType="number"
        android:textColor="@color/primaryTextColor" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

style.xml:

 <style name="mytext" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/green</item>
    <item name="android:textColorHint">@color/green</item>
    <item name="colorAccent">@color/green</item>
    <item name="android:textSize">14sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

编辑:您需要在TextInputLayout中添加textColorHint,它将根据您的需要正常工作.

它对我有用,所以也可以帮到你.