Here is the problem with double hint - TextInputLayout and EditText double hint issue
I need to do the same. I need two hints. One is a title of EditText, and second is a possible value if nothing wasn't input.
But unfortunately there is only one tag:
android:hint
Can I do something with it?
UPD1:
The answer was to set hint for EditText programatically and hint for TextInputLayout in xml.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:hint="@string/prompt_quantity"
android:layout_height="wrap_content">
<EditText
android:id="@+id/quantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
And
quantityEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
quantityEditText.setHint(hasFocus ? "0" : "");
}
});
With the Material Components library you can use
android:hint="Label" to add a floating labelapp:placeholderText="Placeholder Text" to add a placeholder in the EditText.Use something like:
<com.google.android.material.textfield.TextInputLayout
android:hint="Label"
app:placeholderText="Placeholder Text"
..>
<com.google.android.material.textfield.TextInputEditText />
</com.google.android.material.textfield.TextInputLayout>

Note: it requires at least the version 1.2.0-alpha03.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With