Search code examples
androidkotlinandroid-edittexthint

How change upper-hint in MaterialDesign EditText?


I use TextInputEditText and kotlin. I try to change hint programaticaly. But it changed just in box. Add when move-up when i wrote something - upper hint not showing.

I use this code in onCreate:

editTextChooseDate.hint = "Please choose the Date"

and later I check if editTextChooseDate has some test and try to change hint by:

 editTextChooseDate.hint = "Selected Date"

There is editTextChooseDate in xml:

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/layoutEditTextChooseDate"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

    <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/editTextChooseDate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:maxLines="1"/>

</com.google.android.material.textfield.TextInputLayout>

I expected to change upper-hint programaticaly.


Solution

  • You should set second hint to layoutEditTextChooseDate instead of editTextChooseDate. Because "upper-hint" as you called it, is a part of parent container TextInputLayout.