Imagebutton inherits from imageview and button inherits from view.
Compared with imagebutton, button has more powerful functions.
Imagebutton can specify only one image (but also XML) without text, and the button image text can be specified.
In this test, four buttons are used: the common button btn1; The btn2 button with a text background image (with a conversion effect when pressed); the common image button btn3; and The btn4button with a conversion effect.
Test code:
Main. xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/btn1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="press it" /> <Button android:id="@+id/btn2" android:layout_below="@id/btn1" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="exit" android:background="@drawable/button_sel" /> <ImageButton android:id="@+id/btn3" android:layout_below="@id/btn2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/one" android:background="#ffffff"/> <ImageButton android:id="@+id/btn4" android:layout_below="@id/btn3" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_sel" /></RelativeLayout>
Button_sel.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:drawable="@drawable/one"/><item android:state_pressed="false" android:drawable="@drawable/two"/></selector>
:
Initial status: Click exit after the second button: after the fourth button: