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;
}
}
}       
       });
0 0
原创粉丝点击