Olá galera estou tendo dificuldade em fazer com que o botão troque de cor quando os campos EditText
s estiverem preenchidos e voltar a cor inicial quando os campos estivem vazios e também trocar de cor quando pressionado.
Trecho de código presente no 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) {}
});
Propriedade no 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>