保持Textinputlayout提示始终位于顶部 [英] Keep Textinputlayout hint always top

查看:115
本文介绍了保持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.

这篇关于保持Textinputlayout提示始终位于顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆