问题
so far im using something like this
if (image.getDrawable() != thisContext.getResources().getDrawable(R.raw.anImage) ) {
// do something
}
but it does not work.
回答1:
Basically, comparing two drawables is a pain so just convert them to bitmaps and then compare the bitmaps (much easier solution), here's the code:
Bitmap bitmap1 = ((BitmapDrawable)fDraw).getBitmap();
Bitmap bitmap2 = ((BitmapDrawable)sDraw).getBitmap();
if(bitmap1 == bitmap2)
{
do some stuff
}
回答2:
try converting the Drawables to Bitmap first and then comparing:
Bitmap a = ((BitmapDrawable)d1).getBitmap();
Bitmap b = ((BitmapDrawable)d2).getBitmap();
来源:https://stackoverflow.com/questions/12207058/how-can-i-check-if-an-imageview-background-is-a-certain-image