59、常规控件(2)TextInputLayout-让EditText提示更加人性化
2024-08-26 15:12:18
提示语用在显示。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/textInput"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
TextInputLayout textInput = (TextInputLayout) this.findViewById(R.id.textInput);
textInput.setHint("请输入用户名");
final TextInputLayout textInput = (TextInputLayout) this.findViewById(R.id.textInput);
textInput.setHint("请输入用户名"); EditText editText = textInput.getEditText();
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > 10) {
textInput.setError("用户名不能超过10位");
textInput.setErrorEnabled(true);
} else {
textInput.setErrorEnabled(false);
}
}
@Override
public void afterTextChanged(Editable s) {}
});
最新文章
- ssh免密码认证
- [BZOJ2788][Poi2012]Festival
- ZOJ 1122 Clock(模拟)
- 如何设计一个更好的C++ ORM
- Ping命令详解
- UIWebViewでローカルにあるHTMLを表示する&;iOS6からtextAlignmentで指定する値が変更になった
- 导出Ext.grid.Panel到excel
- 论公司spring的滥用
- BZOJ 2276 Temperature
- java 文件操作 写入和读取(小结一)
- python模块(os,sys,hashlib,collections)
- P1494 [国家集训队]小Z的袜子
- Leaflet获取可视范围内4个顶点
- python中的Matplot库和Gdal库绘制富士山三维地形图-参考了虾神的喜马拉雅山
- git hub命令,上传到github
- 《Head First 设计模式》例子的C++实现(2 观察者模式)
- STL学习笔记--排序算法
- 字符串加u的特殊需求
- Java 对象初始化生命周期
- C# 二维码生成——QRCode