保持Textinputlayout提示始终位于顶部
问题描述:
是否可以使我的提示文本始终位于顶部,好像可以聚焦?
Would be possible have my hint text always top, as if it were focusable?
我尝试过:
<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">
答
这是一个技巧-如果文本为空,则以编程方式在文本中添加一个空格.但是,如果您将焦点对准空格,则必须将其删除,否则用户将开始使用前导空格进行键入.另一个选择是总是修剪
用户键入的文本.
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.