2013-04-21 67 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