Hello everyone, I'm having a hard time making the button change color when the% co_of% s fields are filled in and return to the initial color when the fields are empty and also change color when pressed.
Code snippet in EditText
:
senha.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
if(!validar(matricula.getText().toString(), senha.getText().toString())){
//btn_Entrar.setBackgroundColor(Color.parseColor("#c9c9c9"));
btn_Entrar.setClickable(false);
}else if(!matricula.getText().toString().equals("")){
btn_Entrar.setBackgroundColor(Color.parseColor("#2D89db"));
btn_Entrar.setClickable(true);
}
}
public void beforeTextChanged(CharSequence s, int start,int count, int after) {}
public void onTextChanged(CharSequence s, int start,int before, int count) {}
});
XML Property:
android:background="@drawable/shape_edit_text"
shape_edit_text:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_buttonlogin_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/shape_buttonlogin_normal"/>
</selector>
shape_buttonlogin_pressed:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ff0000"/>
</shape>
shape_buttonlogin_normal:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#c9c9c9" />
</shape>