How to get Textinputlayout hint android in multiple lines?

让人想犯罪 __ 提交于 2020-03-18 11:16:23

问题


I have tried many options available online but none of them seem to be working.

I have used this XML for this purpose.

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:hintTextAppearance="@style/TextLabel">

    <com.projects.fonts.RobotoEditText
        style="@style/EditText"
        android:hint="@string/description"
        android:singleLine="false"
        app:font="@string/roboto_regular" />

</android.support.design.widget.TextInputLayout>

I have also set

<item name="android:singleLine">false</item>

in both TextLabel and EditText. But none of them are working.


回答1:


You can't.

TextInputLayout uses CollapsingTextLayout which measures the hint as a CharSequence:

mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length())

CharSequence has no notion of a line, thus you can't add more.


It's not quite a hint if it's so long. If you still want to display it consider adding a separate TextView below/above/over and animating it (if want/need to).




回答2:


In contrast to simas answer it seems that there is a workaround. You can achieve the expected behaviour by setting the hint programmatically in the TextInputEdittext. The downhill is that the floating label does not work after that, by I believe that it is not something that we expect with so long hint.

Important note: If we set the hint to the TextInputLayout, then it will not work.



来源:https://stackoverflow.com/questions/38433838/how-to-get-textinputlayout-hint-android-in-multiple-lines

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