Comparación de los recursos de fondo de los botones
button.setBackgroundResource(R.Drawable.abc); if ( button.getBackground()==getResources().getDrawable(R.drawable.abc)) { button.setBackgroundResource(R.drawable.xyz); } else if( button.getBackground()==getResources().getDrawable(R.drawable.xyz) ) { button.setBackgroundResource(R.drawable.abc); }
Quiero comparar las imágenes de fondo fijadas en el botón. El código anterior se ha tomado de desbordamiento de pila … pero no parece funcionar
Por favor sugiera un mejor método.
Prueba esto
if ( button.getBackground().getConstantState()==getResources().getDrawable(R.drawable.abc).getConstantState()) { button.setBackgroundResource(R.drawable.xyz); }