EditText:文本编辑框
来源:互联网 发布:淘宝网舞鞋 编辑:程序博客网 时间:2024/05/16 11:07
(1)子元素 requestFocus 让某个元素自动获取焦点
(2)hint text为空时显示文字提示信息
(3)TextColorHint 可以通过TextColorHint设置提示信息的颜色
digits 允许输入的文字;
numeric 只能输入数字,有三种值:integer正整数,singed负数,decimal小数;
ems VS maxlength maxlength可以真正控制字符个数。
(4)特殊方式1:(截获与监听输入事件)
EditText editText3=(EditText) findViewById(R.id.editText3);
editText3.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
}
@Override
public void afterTextChanged(Editable s) {
String string=s.toString();
if(string.indexOf("4")!=-1){
s.clear();//clear是全部清空
Toast.makeText(getApplicationContext(), string, 1).show();
}
}
});
(4)特殊方式2:(截获与监听输入事件)
EditText editText1=(EditText) findViewById(R.id.editText1);
editText1.setFilters(new InputFilter[]{
new InputFilter.LengthFilter(5),
new InputFilter.AllCaps(),
new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end,Spanned dest, int dstart, int dend) {
if("1".equals(source.toString())){
return "一";
}else if("2".equals(source.toString())){
return "二";
}else{
return null;
}
}
}
});
(2)hint text为空时显示文字提示信息
(3)TextColorHint 可以通过TextColorHint设置提示信息的颜色
digits 允许输入的文字;
numeric 只能输入数字,有三种值:integer正整数,singed负数,decimal小数;
ems VS maxlength maxlength可以真正控制字符个数。
(4)特殊方式1:(截获与监听输入事件)
EditText editText3=(EditText) findViewById(R.id.editText3);
editText3.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
}
@Override
public void afterTextChanged(Editable s) {
String string=s.toString();
if(string.indexOf("4")!=-1){
s.clear();//clear是全部清空
Toast.makeText(getApplicationContext(), string, 1).show();
}
}
});
(4)特殊方式2:(截获与监听输入事件)
EditText editText1=(EditText) findViewById(R.id.editText1);
editText1.setFilters(new InputFilter[]{
new InputFilter.LengthFilter(5),
new InputFilter.AllCaps(),
new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end,Spanned dest, int dstart, int dend) {
if("1".equals(source.toString())){
return "一";
}else if("2".equals(source.toString())){
return "二";
}else{
return null;
}
}
}
});
0 0
- 文本编辑框用法EditText
- EditText:文本编辑框
- 03 EditText文本编辑框
- Android Textbox Example--EditText 文本编辑框
- Android开发之EditText文本编辑框…
- Android开发之EditText文本编辑框的使用
- 常用UI组件(widgets)之文本编辑框(EditText)(二)
- 文本编辑框
- 文本编辑框--调整文本编辑区域
- Android实现EditText的富文本编辑
- 文本编辑框--背景色
- 创建文本编辑框
- mfc使用文本编辑框
- 文本编辑框自动换行
- FCKeditor 文本编辑框设置
- 重写TEdit文本编辑框
- 仿微博富文本编辑框
- MFC文本编辑框
- C++字符串的重载
- java反射
- 字符编码笔记:ASCII,Unicode和UTF-8
- 字符串操作-各种字符串格式输出转换
- Android 顶部可以伸缩+头部固定+listview下拉刷新、上拉请求更多
- EditText:文本编辑框
- 你为Windows Server 2003终止支持做好准备了吗?
- 利用arm开发板交叉编译opencv249错误汇总
- js guid
- 为什么你写不好一个快速排序?关于
- LeetCode 80 Remove Duplicates from Sorted Array II
- libx264 api example
- 使用Node.js开发一个在线聊天应用——编写前台
- serialVersionUID作用