0
我知道如何改变一个按钮背景图片:如何使用数组(android)中的图像更改按钮背景?
cevap1.setBackgroundResource(R.drawable.image);
但是,我真的想将按钮背景设置为数组中的图像。我怎样才能做到这一点?
cevap1.setBackgroundResource(R.drawable.array [1]);
这当然不起作用。 :))
感谢您的帮助。
我知道如何改变一个按钮背景图片:如何使用数组(android)中的图像更改按钮背景?
cevap1.setBackgroundResource(R.drawable.image);
但是,我真的想将按钮背景设置为数组中的图像。我怎样才能做到这一点?
cevap1.setBackgroundResource(R.drawable.array [1]);
这当然不起作用。 :))
感谢您的帮助。
只是试试这个
int[] myImageList = new int[]{R.drawable.image1, R.drawable.image2};
yourbutton.setBackgroundResource(myImageList[1]);
文件是由Android上的int值确定的,所以你需要创建的int数组的所有资源。
尝试这样
Integer[] image = {
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
R.drawable.pic4,
R.drawable.pic5,
R.drawable.pic6,
R.drawable.pic7
};
,并呼吁
cevap1.setBackgroundResource(image[0]);