edt_phoneNum.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if (s.length() <= 0) {
timeBtn.setFocusable(false);
timeBtn.setBackgroundResource(R.color.lightgray);
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > 0) {
timeBtn.setFocusable(true);
timeBtn.setBackgroundResource(R.color.red);
} else {
timeBtn.setFocusable(false);
timeBtn.setBackgroundResource(R.color.lightgray);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
Android EditText 内容变化监听器
最新推荐文章于 2025-09-24 10:37:52 发布
本文介绍了一段使用TextWatcher监听EditText输入变化的代码实例,根据输入内容的变化动态调整按钮的状态,包括按钮的焦点和背景颜色。
5481

被折叠的 条评论
为什么被折叠?



