我需要获取一些 ImageButton 的背景资源,以便稍后重新使用它,我使用 setBackgroundResource 设置背景。我找不到任何获取背景资源的方法。
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);
}
感谢您的帮助。
最佳答案
对于任何View
,您应该使用getBackground()
,它返回一个Drawable
。
关于java - Android获取ImageButton的背景资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16130797/