Reputation: 263
I want to check if two imageViews match or not , by getting their background from the Drawable .
i did use this way :
if (imgView1.getBackground().getConstantState()
.equals(ContextCompat.getDrawable(getApplicationContext(),R.drawable.myImage)
.getConstantState())
&&
imgView2.getBackground().getConstantState()
.equals(ContextCompat.getDrawable(getApplicationContext(),R.drawable.myImage)
.getConstantState()))
{
// do something
}
it works great on API 23 and API 24 , but not working with API 21 and API 26 ? is there another way to make it work for all android versions?
Upvotes: 1
Views: 3284
Reputation: 3332
try comparing BitmapDrawable of both of them :
Bitmap bitmap = ((BitmapDrawable)imgView1.getDrawable()).getBitmap();
Bitmap bitmap2 = ((BitmapDrawable)imgView2.getDrawable()).getBitmap();
if(bitmap == bitmap2)
{
//Code blcok
}
Upvotes: 2