问题
I have an image button on my view which i need to change after user interaction. I dont find nothing like myImageButton.setDrawable
Here is my xml for the button i want to change:
<ImageButton
android:id="@+id/stopButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/buttons_background"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="@null"
android:src="@drawable/btn_play" />
The only line I need to change android:src="@drawable/btn_play"
to android:src="@drawable/btn_stop"
programmatically. Can this be done? Thanks in advance.
回答1:
You can use
setImageResource for the image button
回答2:
Use this:
myImageButton.setImageResource(R.drawable.btn_stop);
回答3:
ImageButton = (ImageButton)findViewById(R.id.stopButton);
btn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_stop, 0, 0, 0);
回答4:
Use
setImageResource(R.drawable.btn_stop);
来源:https://stackoverflow.com/questions/16526112/how-to-replace-change-image-button-programmatically-android