Android Support Design - TextInputLayout
来源:互联网 发布:过梁算法 编辑:程序博客网 时间:2024/06/07 23:41
TextInputLayout作为一个父容器控件,包装了新的EditText。通常,单独的EditText会在用户输入第一个字母之后隐藏 hint提示信息,但是现在你可以使用TextInputLayout 来将EditText封装起来,提示信息会变成一个显示在EditText之上的floating label,这样用户就始终知道他们现在输入的是什么。
注意
- TextInputLayout不能单独使用,需要包裹EditView组件。
- TextInputLayout的一些属性可以通过xml来设置,例如app:errorEnabled="true"
- hint可以设置给EditText,与TextInputLayout.setHint()设置同样效果.
- error信息只能设置给与TextInputLayout,若设置给EditText,TextInputLayout没有任何变化
- 如果使用app:errorEnabled="true"
来开启error显示,EditText下方将会出现error TextView的占位。所以建议在需要显示error时使用代码开启,用完关闭.
设置hint样式
layout.xml
<android.support.design.widget.TextInputLayout android:id="@+id/til_name" app:errorEnabled="true" app:hintTextAppearance="@style/ErrorText" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/et_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入您的姓名"/></android.support.design.widget.TextInputLayout>
style.xml
<style name="ErrorText" parent="TextAppearance.AppCompat.Small"> <item name="android:textStyle">bold|italic</item> <item name="android:textColor">#00ff00</item></style>
设置字数统计-Counter
app:counterEnabled=”true”
app:counterMaxLength=”10”
<android.support.design.widget.TextInputLayout app:counterEnabled="true" app:counterMaxLength="10" android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入您的邮箱"/></android.support.design.widget.TextInputLayout>
设置Error显示
til_mail= (TextInputLayout) findViewById(R.id.til_mail);et_mail=til_mail.getEditText();et_mail.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { //开启错误显示 til_mail.setErrorEnabled(true); //设置错误显示 til_mail.setError("Error hint,你没有权限输入。"); til_mail.setErrorEnabled(false); }});
api url:http://developer.android.com/reference/android/support/design/widget/TextInputLayout.html
0 0
- Android Support Design - TextInputLayout
- 1.Android support design TextInputLayout
- Android Support Design Library之TextInputLayout
- Android Design Support Library(一)--TextInputLayout简析
- Android Design Support Library--TextInputLayout的使用
- Android Support Design库之TextInputLayout
- Android Design Support Library - TextInputLayout使用
- Error when inflating android.support.design.widget.TextInputLayout
- Android Design Support Library(2)- TextInputLayout的使用
- Android学习之Design Support Library中TextInputLayout的使用
- Android Design Support Library 使用详解二(TextInputLayout)
- Android Support Library-TextInputLayout
- Android Material Design -TextInputLayout
- Design Support Library —— TextInputLayout
- Android:Android Design中的TextInputLayout
- android.support.design.widget包下的CoordinatorLayout、AppBarLayout、TextInputLayout、FloatingActionButton、
- Android Design Support Library(一):FloatingActionButton、TextInputLayout、TextInputEditText简单用法
- Android Design Support Library(一):FloatingActionButton、TextInputLayout、TextInputEditText简单用法
- 最短路径下的Dijkstra算法和Floyd算法
- 连载《一个程序猿的生命周期》- 42.一个时代有一个时代人的使命
- 3.创建简单的UI-Google官网上的Android初学训练
- 二级指针的作用详解
- 通信领域当前的主流技术及社会需求调查报告
- Android Support Design - TextInputLayout
- 如何实现arcgis图层属性字段物理顺序的修改
- android 的view类的setVisibility()
- java的小说展示,下载在查看所有(文件路径找不到,可以修改)
- java界面的面板重绘
- linux中的日志服务syslogd|klogd学习
- UVa 10935-卡片游戏
- 2把数据保存到手机内存、SharedPreferences、内存卡中
- 5.1&&5.2字符大小写转换 加密 'A'+13=N,'Z'+13=M