2

How to set hint of TextInputEditText on top of view.

I have the following edit text that user will type description of the product, but hint is on center of view. enter image description here

Here is the XML code.

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/interestDescriptionView"
    style="@style/TextInputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:maxLines="5"
    app:layout_constraintBottom_toTopOf="@+id/tagsView"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/titleView"
    app:layout_constraintVertical_chainStyle="packed">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/interestDescriptionEditTextView"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:textAlignment="viewStart"
        android:hint="Descrição *"
        android:layout_centerHorizontal="true"
        android:gravity="start|top"
        android:imeOptions="actionDone"
        android:inputType="textMultiLine|textCapSentences"
        android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout>
Zain
  • 37,492
  • 7
  • 60
  • 84
Wellington Yogui
  • 371
  • 3
  • 18
  • 1
    may help: https://stackoverflow.com/questions/40866229/keep-textinputlayout-hint-always-top – Zain Jan 12 '21 at 23:05

1 Answers1

1

You can set android:minLines to 2 or greater .. this will make it work

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/interestDescriptionView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:hint="Descrição *"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textview"
    app:layout_constraintVertical_chainStyle="packed">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/interestDescriptionEditTextView"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_centerHorizontal="true"
        android:gravity="top"
        android:imeOptions="actionDone"
        android:importantForAutofill="no"
        android:inputType="textMultiLine|textCapSentences"
        android:maxLines="5"
        android:minLines="2"
        android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>

Also you can check other workarounds from here

enter image description here

Zain
  • 37,492
  • 7
  • 60
  • 84