Android TextInputLayout 使用
来源:互联网 发布:8寸windows平板电脑 编辑:程序博客网 时间:2024/05/20 07:17
1. 使用
build.gradle
中添加依赖
compile 'com.android.support:design:25.1.0'
2. 布局文件
<android.support.design.widget.TextInputLayout android:id="@+id/til_username" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.design.widget.TextInputEditText android:id="@+id/et_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/username" /></android.support.design.widget.TextInputLayout>
3. 添加图标
<android.support.design.widget.TextInputLayout android:id="@+id/til_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/til_password"> <android.support.design.widget.TextInputEditText ... android:drawableLeft="@drawable/selector_ic_account_circle" android:drawablePadding="4dp" android:drawableStart="@drawable/selector_ic_account_circle" .../></android.support.design.widget.TextInputLayout>
其中,selector_ic_account_circle.xml
内容如下,指定输入框获取焦点和未获取焦点的图标样式,两个图标除颜色外其余相同,图标的制作过程参见 Android 使用 Material icons
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:drawable="@drawable/ic_account_circle_selected_24dp"/> <item android:state_focused="false" android:drawable="@drawable/ic_account_circle_24dp"/></selector>
app:counterEnabled=”true” 可显示输入字数
app:counterMaxLength=”11” 可设置最大可输入字数
对于密码而言,可加入app:passwordToggleEnabled="true"
以显示/隐藏密码
更多可选属性请参考 TextInputLayout
4. 添加错误提示
TextInputLayout til_username = (TextInputLayout) findViewById(R.id.til_username);// 添加错误提示til_username.setError("用户名不能为空");// 取消错误提示til_username.setErrorEnabled(false);
阅读全文
0 0
- android TextInputLayout的使用
- Android TextInputLayout 使用
- android TextInputLayout使用
- Android:TextInputLayout的简单使用
- 【Android-UI】TextInputLayout的使用
- Android TextInputLayout
- android TextInputLayout
- 使用TextInputLayout
- Android Design Support Library--TextInputLayout的使用
- Android TextInputLayout使用,解决setErrorEnabled的bug
- 【Android - MD】之TextInputLayout的使用
- Android:Material Design之TextInputLayout使用
- android之TextInputLayout控件介绍和使用
- Android Design Support Library - TextInputLayout使用
- android 使用TextInputLayout创建一个登陆界面
- Android Design Support Library(2)- TextInputLayout的使用
- Android学习之Design Support Library中TextInputLayout的使用
- Android中Material Desgin风格的Snackbar、TextInputLayout、FloatingActionButton使用
- Java回调学习
- GCD多线程
- 比特位操作——O(1)时间检测2的幂次
- 06_ARM汇编自学笔记指令系统之分类与格式
- Buildroot构建指南--Overview
- Android TextInputLayout 使用
- 在pom.xml中设置maven的镜像为国内镜像
- linux恢复 rm -rf 删除的文件:extundelete
- hbase shell操作之scan+filter
- SharePoint 2016与外部系统人员信息同步(一,Excel数据导入到AD)
- 自建hashMap缓存
- RecyclerView简单的使用
- 关于python的编码问题
- javascript面向对象