简体   繁体   English

BitmapDrawable(如何获取背景图像并与可绘制文件夹中的图像进行比较。)

[英]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. 我想在textview上获取图像背景,并在if语句中进行比较。然后执行一些操作。 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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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