I want a certain action to be done if the image of my ImageButton button
is equal to a drawable. Like this:
if (button.getBackground().getConstantState()==getResources().getDrawable(R.drawable.mydrawable).getConstantState())
{
//perform action//
}
But if I do so, getDrawable
gets red underline and I don't know why?
Can anyone help me?
First
ImageButton temp = findViewById(R.id.myImagebtn);
Bitmap imageBtm = ((BitmapDrawable)temp.getDrawable()).getBitmap();
Drawable myDrawable = getResources().getDrawable(R.drawable.apple);
Bitmap appleBtm = ((BitmapDrawable) myDrawable).getBitmap();
second
if(imageBtm.sameAs(appleBtm))
{
Log.i("Bitmap compare", "equal");
}
getConstantState() doesn't always work.
You could compare if they are equal with their:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.