2011-11-17 88 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 
}