im trying to compare the background of a button to a drawable resource like this:
if (selectedButton.getBackground().getConstantState()
==getResources().getDrawable(R.drawable.bg_default_note_button).getConstantState()){
selectedButton.setBackgroundResource(R.drawable.bg_selected_note_button);
else{
Log.d("1",selectedButton.getBackground().getConstantState.toString());
Log.d("2",getResources().getDrawable(R.drawable.bg_default_note_button).getConstantState.toString());
}
but it will always go to else
statement. it is triggered by a button click and even when the background is bg_default_note_button
it goes to else
.
the log:(when drawable is bg_default_note_button
2020-12-30 11:15:08.958 8952-8952/com.example.weekplanner D/1: android.graphics.drawable.StateListDrawable@af66108
2020-12-30 11:15:08.958 8952-8952/com.example.weekplanner D/2: android.graphics.drawable.StateListDrawable@760a287
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…