You can use TextWatcher to understand if your edittext is filled with text, then change its color if text length is > 0.
In kotlin:
yourEt.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun afterTextChanged(p0: Editable?) {
when (p0?.length) {
0 -> yourEt.setBackgroundColor(Color.parseColor("#FFFFFF"))
else -> yourEt.setBackgroundColor(Color.parseColor("#FFFFCB"))
}
}
})
In java:
yourEt.addTextChangedListener(new 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 (editable.length()>0){
//chnage the edittext background color if filled
yourEt.setBackgroundColor(Color.parseColor("#FFFFCB"))
}else {
//chnage the edittext background color if not filled
yourEt.setBackgroundColor(Color.parseColor("#FFFFFF"))
}
}
});