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?
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?
Do this way
ConstantState constantStateDrawableA = drawableA.getConstantState();
ConstantState constantStateDrawableB = drawableB.getConstantState();
if(constantStateDrawableA.equals(constantStateDrawableB)) {
// do something
} else {
// do something else
}
Try to compare with bytes or pixel is the only way that generally works https://stackoverflow.com/a/36373569/8299619