Keep Textinputlayout hint always top

Here's a hack - programmatically add a space in the text if it's empty. However, you would then have to remove the space if it's focused, else the user will start typing with a leading whitespace. Another option is to always trim the text typed by user.


You can set android:minLines="2" to the TextInputEditText or greater than 2. Also keep android:gravity="top"

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:gravity="top"
        android:hint="Username"
        android:minLines="2" />

Actually, from com.google.android.material:material:1.3.0-alpha03 or higher, you can simply set app:expandedHintEnabled="false" to make it always float.


My final solution back then was to actually just set hintEnabled="false" & use a TextView on top.