Issue
I'm trying to make a state list drawable to be used as a background for an image button.
and my state list selector is like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/play_button_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/play_button_pressed" android:state_focused="true" />
<item android:drawable="@drawable/play_button_normal" />
</selector>
and the image button is like this:
<ImageButton
android:id="@+id/play_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/play_button_bg"
/>
but the button appears as it's having the large image and the background, when clicking on it nothing happens. what can be wrong here?
Solution
Ok, I managed to resolve it using a state list selector with layer lists like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item>
<bitmap android:src="@drawable/play_button_pressed" android:gravity="center" />
</item>
</layer-list>
</item>
<item android:state_focused="true">
<layer-list>
<item>
<bitmap android:src="@drawable/play_button_pressed" android:gravity="center" />
</item>
</layer-list>
</item>
<item android:drawable="@drawable/play_button_normal" />
</selector>
The trick is in the bitmap's: android:gravity="center"
Answered By - Mina Wissa
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.