et_usename = (EditText) findViewById(R.id.et_phone); et_code = (EditText) findViewById(R.id.et_code); bt_register = (Button) findViewById(R.id.bt_register); bt_register.setOnClickListener(this); WatchChange watch = new WatchChange(); et_usename.addTextChangedListener(watch);
et_code.addTextChangedListener(watch);
/** * 自定义监听EditText */ class WatchChange implements TextWatcher { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { if(et_code.length()==4&&et_usename.length()==11){ bt_register.setBackgroundResource(R.drawable.login_background_red); bt_register.setEnabled(true); }else { bt_register.setBackgroundResource(R.drawable.login_background); bt_register.setEnabled(false); } } }