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
  • 31
  • 1
  • 4

2 Answers2

2

Do this way

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

if(constantStateDrawableA.equals(constantStateDrawableB)) {
  // do something
} else {
  // do something else
}
Milan Pansuriya
  • 2,521
  • 1
  • 19
  • 33
0

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

Mohsinali
  • 543
  • 7
  • 14