直接上代码
etNumber.addTextChangedListener(new MyTextWatcher(){
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
super.onTextChanged(s, start, before, count);
int length1 = etpassword.getText().length();
int length2 = s.length();
if (length1>0&&length2>0){
btnLogin.setClickable(true);
btnLogin.setBackgroundResource(R.drawable.selector_login_btn);
}else{
btnLogin.setClickable(false);
btnLogin.setBackgroundResource(R.drawable.shape_login_btn_2);
}
}
});
TextWatcher接口有三个方法 如果不想每次都实现三个方法 或者有的方法用不上 可以直接实现一个类
三个方法分别是监听内容改变之前、内容正在改变、改变之后
public class MyTextWatcher implements 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) {
}
@Override
public void afterTextChanged(Editable s) {
}
}
参数里面传入这个类 重写自己需要的方法就可以了