** * 监听一个EditText的数据的变化来触发Button的颜色变化 * * @date 2018年8月6日 * @author zhang */ public class EdittextWatcher implements TextWatcher { EditText mEditText; Button mButton; private int isPhoneOrQuest; /** * @date 2015年8月13日 * @author liuyonghong */ public EdittextWatcher(int isPhoneOrQuest, EditText editText, Button button) { mEditText = editText; mButton = button; this.isPhoneOrQuest = isPhoneOrQuest; } @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 edit) { if (this.isPhoneOrQuest == 1) { if (edit.toString().trim().length() == 6) { mButton.setBackgroundResource(R.color.white); mButton.setClickable(true); mButton.setEnabled(true); } else { mButton.setBackgroundResource(R.color.title_gray); mButton.setClickable(false); } } else if (this.isPhoneOrQuest == 2) { if (edit.toString().trim().length() != 0) { mButton.setBackgroundResource(R.color.white); mButton.setClickable(true); mButton.setEnabled(true); } else { mButton.setBackgroundResource(R.color.title_gray); mButton.setClickable(false); } }else if(this.isPhoneOrQuest==4){ if (edit.toString().trim().length() != 0) { mButton.setBackgroundResource(R.drawable.banket_btn); mButton.setClickable(true); mButton.setEnabled(true); } else { mButton.setBackgroundResource(R.drawable.banket_btn_hui); mButton.setClickable(false); } } } }
监听一个EditText的数据的变化来触发Button的颜色变化
最新推荐文章于 2020-12-13 22:16:50 发布