1

所以我正在使用 Android 4.0 Library 开发一个 Android 应用程序。

此应用程序的一项活动由具有图像背景和切换按钮的 RelativeLayout 组成。当用户切换按钮时,布局的背景图像必须改变。

所以它必须从activity.java类内部改变:

if (toggleButton.isChecked()){

// Change the background of the activity to image 2 (for example)           
 }

else{ // when toggle button is off

// Change it back to image 1

}

请帮我解决一下这个。谢谢 :)

4

1 回答 1

1

setBackground您在 类中使用该方法View

if (toggleButton.isChecked()){

// Change the background of the activity to image 2 (for example) 
View myView =  this.findViewById(yourViewId); 
myView.setBackgroundResource(yourImage);         
 }

else{ // when toggle button is off

// Change it back to image 1
// Change the background of the activity to image 2 (for example) 
 View myView =  this.findViewById(yourViewId); 
myView.setBackgroundResource(yourOtherImage);
}
于 2013-07-22T23:21:09.543 回答