How to change the floating label color of TextInputLayout

前端 未结 25 1706
[愿得一人]
[愿得一人] 2020-11-22 15:03

With reference to the new TextInputLayout released by Google, how do I change the floating label text color?

Setting colorControlNormal,

相关标签:
25条回答
  • 2020-11-22 15:29

    to change color of the text label when you are focusing on it. i.e. typing in it. you have to add specify

    <item name="android:textColorPrimary">@color/yourcolorhere</item>
    

    Just a note: You have to add all these implementations to your main theme.

    0 讨论(0)
  • 2020-11-22 15:29

    Its Working for me ..... add hint color in TextInputLayout

        <android.support.design.widget.TextInputLayout
            android:textColorHint="#ffffff"
            android:id="@+id/input_layout_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <EditText
                android:id="@+id/edtTextPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:hint="Password"
                android:inputType="textPassword"
                android:singleLine="true"
                />
        </android.support.design.widget.TextInputLayout>
    
    0 讨论(0)
  • 2020-11-22 15:29
      <style name="AppTheme2" parent="AppTheme">
        <!-- Customize your theme here. -->
        <item name="colorControlNormal">#fff</item>
        <item name="colorControlActivated">#fff</item></style>    
    

    add this to styles and set TextInputLayout Theam to App2 and it will work ;)

    0 讨论(0)
  • 2020-11-22 15:29
    <com.google.android.material.textfield.TextInputLayout
        android:hint="Hint"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/TextInputLayoutHint">
    
        <androidx.appcompat.widget.AppCompatEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:maxLines="1"
            android:paddingTop="@dimen/_5sdp"
            android:paddingBottom="@dimen/_5sdp"
            android:textColor="#000000"
            android:textColorHint="#959aa6" />
    
    </com.google.android.material.textfield.TextInputLayout>
    

    res/values/styles.xml

    <style name="TextInputLayoutHint" parent="">
        <item name="android:textColorHint">#545454</item>
        <item name="colorControlActivated">#2dbc99</item>
        <item name="android:textSize">11sp</item>
    </style>
    
    0 讨论(0)
  • 2020-11-22 15:30

    From the documentation:

    The hint should be set on the TextInputLayout, rather than the EditText. If a hint is specified on the child EditText in XML, the TextInputLayout might still work correctly; TextInputLayout will use the EditText's hint as its floating label. However, future calls to modify the hint will not update TextInputLayout's hint. To avoid unintended behavior, call setHint(CharSequence) and getHint() on TextInputLayout, instead of on EditText.

    So I set android:hint and app:hintTextColor on TextInputLayout, not on TextInputEditText and it worked.

    0 讨论(0)
  • 2020-11-22 15:31
    <style name="TextAppearance.App.TextInputLayout" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/red</item>
        <item name="android:textSize">14sp</item>
    </style>
    
    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColorHint="@color/gray"  //support 23.0.0
        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>
    
    0 讨论(0)
提交回复
热议问题