简体   繁体   中英

BitmapDrawable (how to get background image and compare to an image in drawable folder.)

I want get an image background on a textview and compare it in an if statement..and do some actions. this my code.

BitmapDrawable cd = (BitmapDrawable) numberseven.getBackground();
            BitmapDrawable cdeight = (BitmapDrawable) numbereight.getBackground();
            BitmapDrawable cdnine = (BitmapDrawable) numbernine.getBackground();
            BitmapDrawable cdtwelve = (BitmapDrawable) numbertwelve.getBackground();
            BitmapDrawable cdthirteen = (BitmapDrawable) numberthirteen.getBackground();
            BitmapDrawable cdfourteen = (BitmapDrawable) numberfourteen.getBackground();
            BitmapDrawable cdseventeen = (BitmapDrawable) numberseventeen.getBackground();
            BitmapDrawable cdeighteen = (BitmapDrawable) numbereighteen.getBackground();
            BitmapDraw`enter code here`able cdnineteen = (BitmapDrawable) numbernineteen.getBackground();

if(cd.getBitmap()==R.drawable.green){


}

please someone asist.

You can convert your drawable resource to bitmap and compare them

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.green);

if(cd.getBitmap().equals(bitmap)){
    // same
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM