好的,那么当我点击一个按钮时,如何将一张图片更改为另一张图片呢?
我想在按钮按下时更改的图像的xml:
<ImageView
android:id="@+id/bluebtn1"
android:src="@drawable/buttonblue"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="33dp"
android:layout_marginTop="140dp"></ImageView>
当你按下按钮时,这里是我将要执行的Java代码:
case R.id.redbtn1:
if (lvl1.getText().equals("1")) {
lvl1.setText("2");
// Here is where the code goes to change the image
} else {
Toast.makeText(main.this, "YOU LOSE!", Toast.LENGTH_SHORT).show();
}
break;