android输入框内容改变的监听事件一般用于比如我们常见的:登录qq时 用户名输入完整时头像自动显示,或者注册用户时实时提示注册格式是否正确等。那么我们在这里举例:判断输入框是否有内容,来改变按钮的状态,常用于搜索一类。截图如下:(布局代码不再给出)

android输入框内容改变的监听事件_搜索      android输入框内容改变的监听事件_android开发_02

首先所在的activity要 implements TextWatcher并实现其方法:

familyPhonenum.addTextChangedListener(this);
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}


@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!content.isEmpty()) {
textView.setClickable(true);
textView.setEnabled(true);
textView.setTextColor(Color.BLUE);
} else {
textView.setClickable(false);
textView.setEnabled(false);
textView.setTextColor(Color.GRAY);
}
}


@Override
public void afterTextChanged(Editable s) {

}

欢迎关注技术公众号,微信号搜索ColorfulCode 代码男人

分享技术文章,投稿分享,不限技术种类,不限技术深度,让更多人因为分享而受益。

android输入框内容改变的监听事件_android开发_03