Keep Textinputlayout hint always top

ε祈祈猫儿з 提交于 2021-02-08 12:19:44

问题


Would be possible have my hint text always top, as if it were focusable?

I tried this:

 <android.support.design.widget.TextInputLayout
            android:id="@+id/etSurnameInput"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/llNameImage"
            android:hint="My Hint Text"
            app:hintEnabled="true"
            app:hintAnimationEnabled="false"
            android:textColorHint="@color/gray_title">

回答1:


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.




回答2:


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




回答3:


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" />


来源:https://stackoverflow.com/questions/40866229/keep-textinputlayout-hint-always-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!