Reputation: 297
I've use a selector to change the drawable of an ImageView
.
i.e. When the user press the image, the drawable should change.
In layout.xml:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="73dp"
android:src="@drawable/ic_submit_selector" />
ic_submit_selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_submit_pressed" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/ic_submit_pressed" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@drawable/ic_submit" android:state_focused="true"/>
<item android:drawable="@drawable/ic_submit_pressed" android:state_focused="false" android:state_pressed="false"/>
</selector>
But the drawable is not changing.
Upvotes: 1
Views: 830
Reputation: 576
To extend Murtaza's correct answer, if you still wont be able to make it run, try replacing android:src with android:background.
Upvotes: 0
Reputation: 15336
<ImageButton
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="73dp"
android:src="@drawable/ic_submit_selector" />
Not
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="73dp"
android:src="@drawable/ic_submit_selector" />
Upvotes: 1