You need to create custom selectors for the background of the buttons.
This file will live in your XML folder and look something like this (each element describes the background of the button in different selected states):
The file will be called: res / drawable / my_custom_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/blue_button_on" android:state_focused="true" android:state_pressed="true"/> <item android:drawable="@drawable/blue_button_on" android:state_focused="false" android:state_pressed="true"/> <item android:drawable="@drawable/blue_button_off" android:state_focused="true" android:state_pressed="false"/> <item android:drawable="@drawable/blue_button_off" android:state_focused="false" android:state_pressed="false"/> </selector>
Then, to apply this background to your ImageView (or any view), just set it as a background:
<ImageButton android:id="@+id/one" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="0.333" android:adjustViewBounds="true" android:background="@drawable/my_custom_selector" android:contentDescription="@string/description_image_button_one" android:scaleType="fitEnd" android:src="@drawable/dialpad_1" />
source share