2011-11-17 102 views
0

我有两个图像按钮,我想切换彼此的图像,所以按钮a将具有按钮b的图像,而按钮b将具有按钮a的图像。我试图做这在我的代码,但它不工作在android中,你将如何从图像按钮提取图像?

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

你如何setimage for imagebutton? – deepa

回答

2

遵循这样

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 
}