Android修行手册 - TextInputLayout使用学习,字节跳动Android面试全套真题解析在互联网火了

本文介绍了Android5.0之后如何利用MateriaDesign库和JetpackUI库中的TextInputLayout组件创建高效且具有动画效果的UI,包括设置提示信息、计数器和密码提示等功能。作者还分享了相关布局代码和关键属性介绍。
摘要由CSDN通过智能技术生成

image.png

Android在5.0以后引入了Materia Design库的设计,现在又有了Jetpack UI库的设计。帮助开发者更高效的实现炫酷的UI界面,降低开发门槛。

Jetpack我们后面再说,承接之前的EditText,先说说Materia Design里的TextInputLayout。

使用方式是将TextInputEditText或EditText套到TextInputLayout内,这样友情提示信息hit就可以带有动画(上浮为标题),计数/密码可见等属性设置。

布局代码

<com.google.android.material.textfield.TextInputLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:hint=“请输入用户名”>

<EditText

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:inputType=“number” />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginTop=“60dp”

android:hint=“请输入密码”>

<EditText

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:inputType=“textPassword” />

</com.google.android.material.textfield.TextInputLayout>

TextInputLayout效果1.gif

这样就简单的实现了一个效果。我们在继续深入添加些属性:

<com.google.android.material.textfield.TextInputLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:hint=“请输入用户名”

app:hintAnimationEnabled=“false”>

<EditText

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:inputType=“number” />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginTop=“60dp”

android:hint=“请输入密码”

app:counterEnabled=“true”

app:counterMaxLength=“10”

app:passwordToggleEnabled=“true”>

<EditText

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:inputType=“textPassword” />

</com.google.android.material.textfield.TextInputLayout>

从运行结果可以看出,设置了字数限制后,自动在编辑框右下角显示最大字数和当前输入字数(随着输入情况实时变化),并且更改了颜色样式

😜属性介绍

app:boxCollapsedPaddingTop 设置用于编辑文本在框模式下折叠的顶部填充的值

app:boxStrokeErrorColor 在显示错误时设置轮廓框的描边颜色。

app:boxStrokeWidth 设置描边的宽度

app:boxStrokeWidthFocused 设置获取焦点框的描边宽度

app:counterEnabled 是否显示计数器

app:counterMaxLength 设置计数器的最大值,与counterEnabled同时使用

app:counterTextAppearance 计数器的字体样式

app:counterOverflowTextAppearance 输入字符大于我们限定个数字符时的字体样式

app:errorEnabled 是否显示错误信息

app:errorTextAppearance 错误信息的字体样式

app:endIconCheckable 设置是否显示结束图标

app:endIconContentDescription 为结束图标设置内容说明

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

最后

如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。谢谢。

欢迎大家一起交流讨论啊~

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

进的,请给我留言。一定会认真查询,修正不足。谢谢。

[外链图片转存中…(img-4gZzPbQ9-1712380351156)]

欢迎大家一起交流讨论啊~

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

  • 13
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值