1

だから私は Android 4.0 ライブラリを使用して Android アプリケーションに取り組んでいます。

このアプリケーションのアクティビティの 1 つは、イメージの背景とトグル ボタンを持つ 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 に答える