TextInputLayout 基础样式、错误提示、字数限制等等 效果图: 【2020-12-13】Theme切换到MaterialComponents之后,是有一些变化的,比如默认背景、默认padding...布局文件 TextInputLayout android:id="@+id/til_name" android...> TextInputLayout android:id="@+id/til_password".../hint_password" android:inputType="textPassword" /> TextInputLayout...4、密码样式 先设置TextInputEditText android:inputType="textPassword" 然后设置TextInputLayout app:passwordToggleEnabled
---- Implementing TextInputLayout Import the Support Libraries 要使用TextInputLayout控件,你需要导入两个Library。...TextInputLayout控件和LinearLayout完全一样,它只是一个容器。...跟ScrollView一样,TextInputLayout只接受一个子元素。子元素需要是一个EditText元素。...有了TextInputLayout,这将不再是问题。...---- 英文原文请访问: creating-a-login-screen-using-textinputlayout
github地址:https://github.com/shuaijia/MaterialDesignProject 添加依赖 TextInputLayout是在Material Design中的,如果我们要使用的话...,必须在gradle文件中配置 开始使用 TextInputLayout是一种新的继承自LinearLayout的布局,使用时其只能包含一个EditText或其子类控件(如AutoCompleteTextView...) 还可通过设置hint和error来显示浮动标签 注意:一个TextInputLayout中 有且只有 一个EditText!
TextInputLayout的使用 在Gradle的依赖中添加上com.android.support:design:23.0.0,其中23版本根据编译的android版本来调整对应版本即可 ?...gradle配置文件 在对应的Layout文件中使用TextInputLayout将EditText控件包裹,并且在EditText中设置hint属性即可,在这个父ViewGroup中,只能有一个EditText...Layout配置文件 TextInputLayout效果 在两个输入框切换点击切换的时候,EditText中的文本会有动画的方式飞向左上角。 ?...TextInputLayout效果 TextInputLayout动画实现原理 原本以为在点击输入框的时候,会是在EditText的Focus改变的时候,开始执行动画,结果发现是在整个TextInputLayout...TextInputLayout.onLayout 在TextInputLayout中的draw中,会根据onLayout中计算出的CollapsingTextHelper矩形位置以及缩放大小开始绘制文字
文本输入布局TextInputLayout TextInputLayout是MaterialDesign库中对编辑框EditText进行增强的一个控件。...代码中使用TextInputLayout要进行以下改造: 1、添加几个库的支持,包括design库(TextInputLayout需要)、appcompat-v7库(AppCompatActivity)...EditText; 下面是TextInputLayout新增的方法说明: setHint : 设置提示文字的内容。...如果不用TextInputLayout,只使用EditText的话,横屏时的编辑框也会显示提示文字;可是一旦加了TextInputLayout,再看横屏的编辑框,发现编辑框内的提示文字不见了,这是因为TextInputLayout...下面是使用TextInputLayout+EditText的横屏输入页面,可以看到此时编辑框内没有提示文字。 ?
本篇博客带来一个具有强大提示的Material Design风格的控件TextInputLayout,使用这个控件可以非常方便的做出用户登录界面帐号密码输入框的效果,文章将会从以下TextInputLayout...使用和TextInputLayout源码分析两个方面对这个强大的控件进行分析。...TextInputLayout的使用 这里使用TextInputLayout简单写一个登录的界面 布局代码 textInputLayout; public MinLengthTextWatcher(TextInputLayout textInputLayout, String errorStr...()用于给textInputLayout包裹的EditText设置内容变化监听,我们可以自己重写一个监听实现里面的方法进行相关逻辑的处理 效果如下: TextInputLayout源码分析 TextInputLayout
零、前言 这是两个比较小的点,放在一起说一下: 沉浸标题栏:现在基本上都用沉浸标题栏了,不然最顶的一小块跟app风格不搭 TextInputLayout:包裹一个EditeText,多用于登陆验证的输入框... 使用:给Activity设置主题即可 android:theme="@style/TranslucentTheme" ---- 二、TextInputLayout...TextInputLayout.png TextInputLayout android:id="@+id/til2"...android:textColorHint="@color/white" /> TextInputLayout
如果我们想写一个登陆界面是不是一般都写两组TextView,EditText及一个Button,不过体验并不是太好,等等这些麻烦的的处理在Material Design TextInputLayout...可以看到并不是非常美观,下载我们引入 TextInputLayout 稍作改动 ---- 使用 TextInputLayout 我们终于到达了本教程中最有趣的部分。...一个 TextInputLayout 小部件的行为与LinearLayout它完全一样,它只是一个包装器。TextInputLayout只接受一个子元素,类似于a ScrollView。...final TextInputLayout usernameWrapper = findViewById(R.id.usernameWrapper); final TextInputLayout...---- 显示错误 TextInputLayout 错误处理简单快捷。所需的方法是 setErrorEnabled和setError。
TextInputLayout TextInputLayout继承LinearLayout,因此我们需要将EditView包含在TextInputLayout之内才可以使用,言外之意:TextInputLayout...TextInputLayout常用的方法有如下: setHint():设置提示语。 getEditText():得到TextInputLayout中的EditView控件。...特别注意:TextInputLayout不能单独使用,必须包裹EditView组件,且只能一个,设置错误提示信息时一定要先setErrorEnabled(true);再设置setError()。...TextInputEditText TextInputEditText和TextInputLayout类似,Design包还有一个组件TextInputEditText,它继承了AppCompatEditText
TextInputLayout是22.2.0新添加的控件, 要和EditText(或EditText的子类)结合使用,并且只能包含一个EditText(或EditText的子类)。...这时候TextInputLayout则是显示错误,TextInputLayout是LinearLayout的子类,用于辅助显示提示信息。...现在仅仅是过度效果,还没有加提示信息,用法很简单,但注意一点TextInputLayout只能包含一个TextInputEditText,如果写用户名和密码那就写两个TextInputLayout,哦,...TextInputLayout android:id="@+id/id_inputtext" android...> 这里要注意的是Id是加在 TextInputLayout上,在Activity中获取也是获取的layout,那么怎么获取edittext输入的数据呢,有方法的。
和TextInputEditText创建用户名和密码输入的字段: TextInputLayout android:layout_width...> TextInputLayout android:id="@+id/password_tv_input" android...主要功能是错误反馈,代码业务逻辑实现错误提示,设置密码字段类型为“textPassword”: TextInputLayout...> TextInputLayout android:id="@+id/password_tv_input" android...四、学习笔记 在开发过程中,积累了MDC框架技术的学习心得: 4.1.Material Components (MDC) 深入学习了MDC组件如TextInputLayout、MaterialButton
layout_marginStart="34dp" android:background="@color/divider"/> TextInputLayout...font_title" android:textSize="@dimen/font_normal"/> TextInputLayout...layout_marginStart="34dp" android:background="@color/divider"/> TextInputLayout...20" android:textSize="@dimen/font_normal"/> TextInputLayout...font_title" android:textSize="@dimen/font_normal"/> TextInputLayout
background="@color/white" android:hint="账号" /> com.google.android.material.textfield.TextInputLayout...> TextInputLayout android:layout_width="match_parent...hint="密码" android:inputType="textPassword" /> com.google.android.material.textfield.TextInputLayout...> TextInputLayout android:layout_width="match_parent...> TextInputLayout android:layout_width="match_parent
要恢复为旧的文本字段可以在布局中添加样式 TextInputLayout ... + style="@style.../Widget.Design.TextInputLayout"> ......TextInputLayout> 或者你也可以在主题中给所有的文本设置默认样式 +TextInputLayout” parent=”Widget.Design.TextInputLayout”> +...TextInputEditText Widget.Design.TextInputLayout Widget.MaterialComponents.TextInputLayout.* textInputStyle
layout_height="match_parent" android:orientation="vertical"> TextInputLayout...singleLine="true" android:text="@={userModel.username}" /> TextInputLayout...> TextInputLayout android:id="@+id/passwordLayout"...textPassword" android:text="@={userModel.password}" /> TextInputLayout
="vertical" android:padding="32dp"> TextInputLayout...500" android:textSize="24sp" /> TextInputLayout...> TextInputLayout android:id="@+id...> TextInputLayout android:id="@+id...> TextInputLayout android:layout_width
textColor="@color/black" android:textSize="12sp" /> com.google.android.material.textfield.TextInputLayout...> TextInputLayout android:layout_width="match_parent...textColor="@color/black" android:textSize="12sp" /> com.google.android.material.textfield.TextInputLayout...> TextInputLayout android:layout_width="match_parent...> TextInputLayout android:layout_width="match_parent
Snackbar的详细使用参见《轻量级控件SnackBar使用以及源码分析》 TextInputLayout 布局: TextInputLayout...需要注意的是,TextInputLayout必须包含一个EditText。...textInputLayout, String errorString, int maxTextCount) { mTextInputLayout = textInputLayout...在TextInputLayout可以轻松地通过getEditText方法找到它所包裹的EditText。、 在显示错误的时候,需要先设置错误的提示,每次显示的时候都要设置。...TextInputLayout详细使用请参见强大的提示控件TextInputLayout使用以及源码分析 Toolbar <android.support.v7.widget.Toolbar android
领取专属 10元无门槛券
手把手带您无忧上云