2013-04-21 62 views
3

我需要獲取某些ImageButton的後臺資源,稍後重新使用它,以設置我使用setBackgroundResource的背景。我沒有找到任何方法來獲得背景源。Android獲取ImageButton的背景資源

private void AddImage(int img){ 
    ImageButton imgact1 = (ImageButton)findViewById(R.id.imgact1); 
    ImageButton imgact2 = (ImageButton)findViewById(R.id.imgact2); 
    ImageButton imgact3 = (ImageButton)findViewById(R.id.imgact3); 
    imgact3.setBackgroundResource(img); 
} 

感謝您的幫助。

+0

http://developer.android.com/reference/android/widget/ImageButton.html – Raghunandan 2013-04-21 14:10:34

回答

3

至於任何View,您應該使用getBackground(),它將返回Drawable

+0

感謝您的回答, – 2013-04-21 13:15:01

+0

@達僧,不客氣。如果您發現它有幫助,請不要忘記接受答案。 – Egor 2013-04-21 15:29:09

+0

如何將該值存儲在字符串中?如果圖像在'android:src'中定義,我該怎麼辦?謝謝! PS:我有upvoted – 2015-11-28 21:20:22