3
Hello guys I’m having trouble getting the button to change color when the fields EditTexts are filled and return the initial color when the fields are empty and also change color when pressed.
Excerpt from code present in onCreate:
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) {}
});
Property in XML:
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>