当前位置:网站首页>Textinputlayout usage details
Textinputlayout usage details
2022-06-10 13:47:00 【yechaoa】
TextInputLayout Basic style 、 Error message 、 Word limit, etc
design sketch :
【2020-12-13】Theme Switch to MaterialComponents after , There are some changes , Such as default background 、 Default padding etc. , Specific changes can be made github see .
Layout file
<android.support.design.widget.TextInputLayout
android:id="@+id/til_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:counterEnabled="true"
app:counterMaxLength="3"
app:counterOverflowTextAppearance="@style/MyOverflowText"
app:errorEnabled="true"
app:errorTextAppearance="@style/MyErrorText"
app:hintTextAppearance="@style/MyHintText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/include">
<android.support.design.widget.TextInputEditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_name"
android:theme="@style/MyEditText" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/til_password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/til_name"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/colorPrimary">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>1、 Change the default style
- style:
<!--Floating label text style-->
<style name="MyHintText" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">@color/colorPrimary</item>
</style>
<!--Input field style-->
<style name="MyEditText" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">@color/gray</item>
<item name="colorControlActivated">@color/colorPrimary</item>
<item name="android:textSize">18sp</item>
</style>- And then set the
TextInputLayout:
app:hintTextAppearance="@style/MyHintText"TextInputEditText:
android:theme="@style/MyEditText"2、 Error prompt style and code settings
- style:
<!--Error label text style-->
<style name="MyErrorText" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">@color/red</item>
</style>- Then set the
app:errorEnabled="true"
app:errorTextAppearance="@style/MyErrorText"Code control , Set input listening
mEtName.addTextChangedListener(mTextWatcher);
---------------------------------------------
private TextWatcher mTextWatcher = 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) {
if (mTilName.getEditText().getText().length() > mTilName.getCounterMaxLength())
mTilName.setError(" The input exceeds the upper limit ");//show
else
mTilName.setError(null);//hide
}
};3、 Word limit
- style:
<!--Overflow label text style-->
<style name="MyOverflowText" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">@color/orange</item>
</style>- Then set the
app:counterEnabled="true"
app:counterMaxLength="3"
app:counterOverflowTextAppearance="@style/MyOverflowText"You can understand the literal meaning of the word , Let's not explain them one by one ..
Above “ Error message ” in , There is a judgment that
if (mTilName.getEditText().getText().length() > mTilName.getCounterMaxLength())- mTilName yes TextInputLayout,getEditText() Method to get child controls TextInputEditText.
- getCounterMaxLength() Method to get the maximum word limit .
4、 Password style
- First set up TextInputEditText
android:inputType="textPassword"- Then set the TextInputLayout
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/colorPrimary"- app:passwordToggleTint Is to change the color of the icon
- Change icon yes app:passwordToggleDrawable
app:passwordToggleDrawable="@drawable/ic_password"github:
边栏推荐
- How to solve the problem that vmware tools are grayed out when VMware Workstation is installed
- 解决VMware Workstation安装VMware Tools显示灰色的办法
- In depth analysis of "circle group" relationship system design | series of articles on "circle group" technology
- [Netease Yunxin] in depth analysis of the design of "circle group" message system | series of articles on "circle group" technology
- buuctf [PHP]XDebug RCE
- 618 大促来袭,浅谈如何做好大促备战
- 2022 high frequency software test interview questions of large factories (with answers)
- 让资源在云端和本地自由流动
- [cloud computing] what is the relationship between a multi cloud management platform and a public cloud?
- 【操作教程】如何正确使用海康demo工具配置通道上线?
猜你喜欢

新功能|Mail GPU Counter模块新增GPU图元处理和GPU Shader Cycles

将anaconda的bin目录加入PATH

「大模型」之所短,「知识图谱」之所长

【技术分析】探讨大世界游戏的制作流程及技术——前期流程篇

New features mail GPU counter module adds GPU primitive processing and GPU shader cycles

H. 265 introduction to coding principles

高性能实战Alibaba Sentinel笔记,深度还原阿里微服务高并发方案
![buuctf [Jupyter]notebook-rce](/img/fc/9c2047bdadb606b555e48f553fb1dd.png)
buuctf [Jupyter]notebook-rce
10 competitive airpods Pro products worth your choice

Google Earth Engine(GEE)——基于s2影像的实时全球10米土地利用/土地覆盖(LULC)数据集
随机推荐
Copying and deleting files
[operation tutorial] how to correctly use the Hikvision demo tool to configure the channel to go online?
【FAQ】运动健康服务REST API接口使用过程中常见问题和解决方法总结
Record common functions in MySQL at work
Recommend an efficient IO component - okio
超详细的FFmpeg安装及简单使用教程
Gree mobile phone challenge Apple mobile phone? I'm afraid there's nothing else but hard talk
[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service
【云计算】多云管理平台和公有云两者之间是啥关系?
[technical analysis] discuss the production process and technology of big world games - preliminary process
618. How to prepare for the great promotion
Can qiniu open an account? Can the security of securities companies be directly opened on the app
3. web page development tool vs Code
How to locate the hot problem of the game
What are the common automated test frameworks? Shanghai software testing company Amway
What can the graph of training and verification indicators tell us in machine learning?
高性能实战Alibaba Sentinel笔记,深度还原阿里微服务高并发方案
Sohu employees encounter wage subsidy fraud. What is the difference between black property and gray property and how to trace the source?
大四应届毕业生,想自学软件测试,如何应对面试?
10 competitive airpods Pro products worth your choice