9

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.

4

4 回答 4

12

You can use

setImageResource for the image button
于 2013-05-13T15:52:19.487 回答
10

Use this:

myImageButton.setImageResource(R.drawable.btn_stop);
于 2013-05-13T15:50:53.903 回答
3
ImageButton = (ImageButton)findViewById(R.id.stopButton);
btn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_stop, 0, 0, 0);
于 2013-05-13T15:52:45.267 回答
2

Use

setImageResource(R.drawable.btn_stop);

于 2013-05-13T15:54:55.400 回答