前几天在某个app的注册界面发现当编辑框获得焦点的时候,hintText会自动上浮,当时觉得这app做的还挺好的,居然还设置了动画效果。
结果后来百度了一下,发现居然是google提供的support库里自带的。。只能说当时自己没关注google的I/O发布会
于是回家研究了TextInputLayout的用法,来和大家分享。
/**
* Layout which wraps an {@link android.widget.EditText} (or descendant) to show a floating label
* when the hint is hidden due to the user inputting text.
*
* Also supports showing an error via {@link #setErrorEnabled(boolean)} and
* {@link #setError(CharSequence)}, and a character counter via
* {@link #setCounterEnabled(boolean)}.
*
* The {@link TextInputEditText} class is provided to be used as a child of this layout. Using
* TextInputEditText allows TextInputLayout greater control over the visual aspects of any
* text input. An example usage is as so:
*
*
*
*
*
*
*
*
*/
以上是TextInputLayout的官方说明,大概意思是TextInputLayout支持三个feature:
1 当用户输入的时候,可以显示hintText动画。
2 可以为EditeText设置错误提示信息。
3 可以为EditText设置计数功能。
而用法仅仅是提供一个EditText作为TextInputLayout的子类即可。