59、常规控件(2)TextInputLayout-让EditText提示更加人性化
控件 提示 更加 常规 EditText 59
2023-09-14 09:00:21 时间
提示语用在显示。
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="match_parent" 3 android:layout_height="match_parent" 4 android:layout_margin="20dp" 5 android:orientation="vertical"> 7 <android.support.design.widget.TextInputLayout 8 android:id="@+id/textInput" 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content"> 11 <EditText 12 android:layout_width="match_parent" 13 android:layout_height="wrap_content" /> 14 </android.support.design.widget.TextInputLayout> 16 </LinearLayout>
TextInputLayout textInput = (TextInputLayout) this.findViewById(R.id.textInput);
textInput.setHint("请输入用户名");
1 final TextInputLayout textInput = (TextInputLayout) this.findViewById(R.id.textInput); 2 textInput.setHint("请输入用户名"); 3 4 EditText editText = textInput.getEditText(); 5 editText.addTextChangedListener(new TextWatcher() { 6 @Override 7 public void beforeTextChanged(CharSequence s, int start, int count, int after) {} 11 @Override 12 public void onTextChanged(CharSequence s, int start, int before, int count) { 13 if (s.length() > 10) { 14 textInput.setError("用户名不能超过10位"); 15 textInput.setErrorEnabled(true); 16 } else { 17 textInput.setErrorEnabled(false); 18 } 19 } 21 @Override 22 public void afterTextChanged(Editable s) {} 25 });
相关文章
- wxpython自定义控件_wxPython 教程(十三) 自定义控件
- FileUpload文件上传控件「建议收藏」
- Android短信验证码控件,Android中实现短信验证码自动填入
- UpdatePanel 控件
- c#常用表格控件dataGridView的分页显示的案例分享
- dropdownlist控件绑定_dropdownlist控件联动
- WPF中用户控件和自定义控件
- java 一款可以与ssm框架完美整合的web报表控件详解编程语言
- abap调vb写的dll实现电子天平的读数(带控件版)详解编程语言
- asp.net自定义控件回发数据实现方案与代码
- 利用委托把用户控件的值显示于网页案例应用
- 获得.net控件的windows句柄的方法
- js获取控件位置以及不同浏览器中的差别介绍
- Jquery插件分享之气泡形提示控件grumble.js
- asp控件和html控件的概念区别