简体   繁体   中英

in android, how would you extract the image from a imagebutton?

I have two imagebutton and I want to switch the image of each other so button a will have button b's image while button b will have button a's image. I tried to do this in my code, but it does not work

Bitmap temmp = a1.getDrawingCache();
a1.setImageBitmap(a2.getDrawingCache());
a2.setImageBitmap(temmp);

follow like this

buttona.setOnClickListener(new View.OnClickListener()  {            
  public void onClick(View v)  { 
    ImageButton ib = (ImageButton)v;  
    Drawable d11 = ib.getDrawable(); // this is the image u can get from that button
} 

在使用getDrawingCache() setDrawingCacheEnabled(true)调用getDrawingCache()之前,需要启用图形缓存

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