I want to change the drawable resource file at runtime.
.java file code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.button);
edt1 = (EditText)findViewById(R.id.name);
edt2 = (EditText)findViewById(R.id.password);
str_name = edt1.getText().toString() ;
str_password = edt2.getText().toString();
if (str_name == 0 && str_password == 0) {
btn.setBackgroundResource(R.drawable.image);
}
else {
btn.setBackgroundResource(R.drawable.on_button_click);
}
The thing is that it applies the if
condition but when I enter some text in the EditText
the resource file does not change.
EditText
(s) are under TextInputLayout
.