监听一个EditText的数据的变化来触发Button的颜色变化

**
 * 监听一个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);
   }
  }
 }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值