Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to make double hint in EditText with TextInputLayout

Tags:

android

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" : "");
        }
    });
like image 243
Sergey Android Avatar asked Oct 22 '25 16:10

Sergey Android


1 Answers

With the Material Components library you can use

  • android:hint="Label" to add a floating label
  • app: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>

enter image description here

Note: it requires at least the version 1.2.0-alpha03.

like image 93
Gabriele Mariotti Avatar answered Oct 25 '25 07:10

Gabriele Mariotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!