-1

I want to compare drawable image with menu item icon.

For example I want to like this

if(item.getIcon().equals(getDrawable(R.drawable.image))){
     ... 

}

but it doesn't work in android studio. How can I compare two drawable images?

userssss1
  • 11
  • 1
  • 3

2 Answers2

1

Do this way

 ConstantState constantStateDrawableA = drawableA.getConstantState();
ConstantState constantStateDrawableB = drawableB.getConstantState();

if(constantStateDrawableA.equals(constantStateDrawableB)) {
  // do something
} else {
  // do something else
}
Milan Pansuriya
  • 2,402
  • 1
  • 17
  • 31
0

Try to compare with bytes or pixel is the only way that generally works https://stackoverflow.com/a/36373569/8299619

Mohsinali
  • 503
  • 6
  • 12