Android Design Support Library 使用详解二(TextInputLayout)
来源:互联网 发布:批发零售软件 编辑:程序博客网 时间:2024/06/06 02:02
TextInputLayout作为一个父容器控件,包装了新的EditText。通常,单独的EditText会在用户输入第一个字母之后隐藏hint提示信息,但是现在你可以使用TextInputLayout 来将EditText封装起来,提示信息会变成一个显示在EditText之上的floating label,这样用户就始终知道他们现在输入的是什么。同时,如果给EditText增加监听,还可以给它增加更多的floating label。
下面我们来看这与一个TextInputLayout:
<android.support.design.widget.TextInputLayout android:id="@+id/til_pwd" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content"/></android.support.design.widget.TextInputLayout>一定要注意,他是把EditText包含起来的,不能单独使用。
在代码中,我们给它设置监听:
final TextInputLayout textInputLayout = (TextInputLayout) findViewById(R.id.til_pwd); EditText editText = textInputLayout.getEditText(); textInputLayout.setHint("Password"); editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { if (s.length() > 4) { textInputLayout.setError("Password error"); textInputLayout.setErrorEnabled(true); } else { textInputLayout.setErrorEnabled(false); } } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { } }); }
0 0
- Android Design Support Library 使用详解二(TextInputLayout)
- Android Design Support Library--TextInputLayout的使用
- Android Design Support Library - TextInputLayout使用
- Android Design Support Library(2)- TextInputLayout的使用
- Android进阶系列--Design Support Library使用详解(Snackbar,TextInputLayout,TabLayout,NavigationView...)
- Android进阶系列--Design Support Library使用详解(Snackbar,TextInputLayout,TabLayout,NavigationView...)
- Android Design Support Library使用详解(二)
- Android学习之Design Support Library中TextInputLayout的使用
- Android Design Support Library使用详解——TextInputLayout与TextInputEditText
- Android Design Support Library使用详解——TextInputLayout与TextInputEditText
- Android Support Design Library之TextInputLayout
- Android Design Support Library(一)--TextInputLayout简析
- Android Design Support Library使用详解
- Android Design Support Library使用详解
- Android Design Support Library使用详解
- Android Design Support Library使用详解
- Android Design Support Library使用详解
- Android Design Support Library使用详解
- Storm的ack机制
- 转:使用python的Flask实现一个RESTful API服务器端
- AJAX工作原理及其优缺点
- 如何转载他人的博客
- 详解MATLAB之MAX函数
- Android Design Support Library 使用详解二(TextInputLayout)
- maven安装和与IDE集成
- Oracle中的rownum,ROWID的 用法
- 自己动手写DB数据库框架(增)
- leetcode414~Third Maximum Number
- Java学习之HashMap
- codevs贪心 地鼠游戏
- LSTM模型与前向反向传播算法
- java中使用Jedis操作Redis