With reference to the new TextInputLayout
released by Google, how do I change the floating label text color?
Setting colorControlNormal
,
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.
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>
<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 ;)
<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>
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.
<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>