//EditText的监听
mEd.addTextChangedListener(watcher);
//监听输入框软键盘 达到8位就变颜色
private TextWatcher watcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
if (s.length()==8){
//当输入到8位时自动关闭软键盘
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mEd.getWindowToken(),0);
//到8位时是蓝色
mButton.setBackgroundColor(Color.parseColor("#499aec"));
}else {
//没到8位是灰色
mButton.setBackgroundColor(Color.parseColor("#adb4ba"));
}
}
};
//在布局里设置输入框固定长度是:
android:maxLength="8"