TextInputLayout not showing EditText hint before user focus on it
Update:
This is a bug that has been fixed in version 22.2.1 of the library.
Original Answer:
As mentioned by @shkschneider, this is a known bug. Github user @ljubisa987 recently posted a Gist for a workaround:
https://gist.github.com/ljubisa987/e33cd5597da07172c55d
As noted in the comments, the workaround only works on Android Lollipop and older. It does not work on the Android M Preview.
EditText not showing the hint or the outline box until focused
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
app:hintTextColor="@color/black"
app:boxStrokeColor="@color/black"
android:layout_marginTop="20dp"
app:boxStrokeWidth="2dp"
android:textColorHint="@color/black"
>
<EditText
android:id="@+id/etInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
/>
</com.google.android.material.textfield.TextInputLayout>
TextInputLayout not showing hint while typing
Try this Define style
<style name="TextInputLayoutLabelGrey" parent="Widget.Design.TextInputLayout">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">@color/your_color</item>
<item name="android:textColor">@color/your_color</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">@color/your_color</item>
<item name="colorControlNormal">@color/your_color</item>
<item name="colorControlActivated">@color/your_color</item>
</style>
Your layout xml
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/TextInputLayoutLabelGrey">
<android.support.v7.widget.AppCompatEditText
android:id="@+id/et_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="@string/id_hint"/>
</android.support.design.widget.TextInputLayout>
Hint not visible with TextInputLayout on non focus state
This issue is fixed as of 22.2.1, update your Android SDK.
Android 4.2 Material TextInputLayout hint not showing in rtl mode
Finally I fixed it.
I used newest library of material design
com.google.android.material:material:1.2.0-alpha02
I changed it to
com.google.android.material:material:1.1.0-alpha05
and everything is well.
Change TextInputLayout hint text after focused
To change hint text color Use View.OnFocusChangeListener
to set the hintTextAppearance
. Try the config below.
<style name="inactive" parent="Theme.AppCompat.Light">
<item name="android:textColorPrimary">@android:color/darker_gray</item>
<item name="android:textColor">@android:color/darker_gray</item>
</style>
<style name="active" parent="Theme.AppCompat.Light">
<item name="android:textColorPrimary">@android:color/black</item>
<item name="android:textColor">@android:color/black</item>
</style>
XMl
<android.support.design.widget.TextInputLayout
android:id="@+id/tet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/et"
app:hintTextAppearance="@style/inactive"
android:layout_margin="@dimen/activity_horizontal_margin"
app:hintEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:textColor="@color/colorPrimary"
android:layout_height="wrap_content"
android:hint="Floating Hint" />
</android.support.design.widget.TextInputLayout>
Change the style during focus change.
final TextInputLayout inputLayout=findViewById(R.id.tet);
final TextInputEditText edit=findViewById(R.id.edit);
edit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
inputLayout.setHintTextAppearance(R.style.active);
else
inputLayout.setHintTextAppearance(R.style.inactive);
}
});
EDIT:- To change Hint text only you can just change it on focus change.
edit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
edit.setHint("Enter name");
else
edit.setHint("Name");
}
});
Related Topics
How to Create Tests in Android Studio
Play Sound on Button Click Android
Creating Viewholders for Listviews with Different Item Layouts
Android SQLite: Update Statement
Android Adb Stop Application Command Like "Force-Stop" for Non Rooted Device
How to Delete SQLite Database from Android Programmatically
Broadcast Receiver Not Working After Device Reboot in Android
Fragments Destroyed/Recreated with Jetpack's Android Navigation Components
Android Room: Insert Relation Entities Using Room
Android How to Create Runtime Thumbnail
Using Disklrucache in Android 4.0 Does Not Provide for Opencache Method
Android View Not Attached to Window Manager
Android: Tabhost Without Tabactivity
Load an Image from Assets Folder
How to Check Whether the Sim Card Is Available in an Android Device