TextInputLayout
为什么80%的码农都做不了架构师?>>>
TextInputLayout
TextInputLayout 是一个布局,仅可以添加一个子View且必须为ExitText。
TextInputLayout 为用户提供了两个比较有意思的方法
1.hint是EditText的一个很好的属性,当用户输入数据后,hint内容将自动消失。使用TextInputLayout用户输入数据后内容将不会直接隐藏,而是上浮继续显示;
2.用户输入信息错误,错误提示将直接显示在输入EditText下发。
示例代码:
布局代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/original_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/section_label"
android:hint="请输入密码"
/>
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/original_edittext"
>
<EditText
android:id="@+id/Test_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.TextInputLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/text_input_layout"
android:hint="请输入密码"
/>
</RelativeLayout>
Java代码:
final TextInputLayout textInputLayout = (TextInputLayout) rootView.findViewById(R.id.text_input_layout);
textInputLayout.setHint("请输入帐号"); //动态设置hint信息,尝试在布局中进行设置为成功
textInputLayout.getEditText().setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
textInputLayout.setError("格式有误"); //自动设置setErrorEnabled为true
} else {
textInputLayout.setErrorEnabled(false); //设置错误信息提示。由于提示信息是需要占据一定位置,因此这里设置错误提示不可用
textInputLayout.setError(null); //设置错误提示信息为空
}
}
});
转载于:https://my.oschina.net/smuswc/blog/598957
TextInputLayout相关推荐
- 使用TextInputLayout分分钟构造一个酷炫登录框架
Google在2015的IO大会上,给我们带来了更加详细的Material Design设计规范,同时,也给我们带来了全新的Android Design Support Library,Android ...
- 安卓Design包下的TextInputLayout和FloatingActionButton的简单使用
终于介绍到Design包的最后的东西了. 也很简单,一个是TextInputLayout. TextInputLayout作为一个父容器,包含一个新的EditText,可以给EditText添加意想不 ...
- Android 带有字数统计的 TextInputLayout
带有字数统计的 TextInputLayout 转载于:https://www.cnblogs.com/zhujiabin/p/5784378.html
- android design包控件,Android Design包之TextInputLayout和TextInputEditText的组合使用【原创】...
在Android的日常开发中,EditText是个不可或缺的控件之一,作为输入框,用法也没什么太多值得可说的,拿一个简单的登录界面为例,平时差不多是这样的布局: 一般来说是这样,EditText里面的 ...
- Android开发2:事件处理及实现简单的对话框(Toast,AlertDialog,Snackbar,TextInputLayout的使用)...
前言 啦啦啦~又要和大家一起学习Android开发啦,博主心里好激动哒~ 在上篇博文中,我们通过线性布局和基础组件的使用,完成了一个简单的学生课外体育积分电子认证系统的界面,本篇博文,将和大家一起熟悉 ...
- Android开发笔记(一百三十八)文本输入布局TextInputLayout
文本输入布局TextInputLayout TextInputLayout是MaterialDesign库中对编辑框EditText进行增强的一个控件.众所周知,EditText未输入字符时,我们可以 ...
- android jni示例_Android TextInputLayout示例
android jni示例 In this tutorial, we'll be looking in depth at the features that Android TextInputLayo ...
- TextInputLayout字数统计功能
TextInputLayout字数统计功能实现 效果演示 图示可以看出,字数统计和浮动标签显示分为两种状态,一是字数未满的状态,图中显示的是红色,二是字数满了之后的状态,图中显示的是蓝色.这两种状态都 ...
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
在前不久的谷歌2015 I/O大会上,发布了Android新版本M,貌似从这个版本开始Android不在以数字命名版本了. 在这次的I/O大会上谷歌对Android并没有很大的改变,主要是修改完善之前 ...
最新文章
- 华为云交付项目服务器配置表,云端服务器配置表
- Xamarin.Android提示aapt退出,代码为255
- 如何用杠铃策略,构建你的“反脆弱性”
- 关于maven依赖中的scopeprovided/scope使用
- 如何接触到最新的前端动态、最前沿的前端技术
- Anaconda——conda换源可以直接通过conda命令来实现
- Linux MySQL主主复制(Replication)(MySQL数据双向同步)配置
- mysql 拼sql_在MySQL中拼SQL语句
- 图片不能有透明通道AppStore images can't contain alpha channels or transparencies windows iOS
- 现代城市生态与环境学
- tapd获取相应内容
- 第一篇博客-Sql排名函数DENSE_RANK
- v-if和v-show能和v-for同时出现吗?
- 逃不开的安迪-比尔定律,在智能机器人时代该如何破解?
- hidapi在linux下编译,HIDAPI
- 俞敏洪:《中国合伙人》
- 高级android开发工程师机会---纽交所上市互联网公司
- ninja 编译系统
- 破壁人AI百度:科技公司反内卷的典型样本
- Redis(2):持久化