Android Widget – ImageButton

android image viewAn ImageButton is an AbsoluteLayout which enables you to specify the exact location of its children. This shows a button with
an image (instead of text) that can be pressed or clicked by the user.

Add ImageButton

Open “your.xml” file, just add an ImageButton .

Creating a ImageButton in a Layout File
<!--?xml version="1.0" encoding="utf-8"?-->
<linearlayout xmlns:android="" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
    <imagebutton android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/android_button">

Here’s the code, add a click listener on image button.

public class MainActivity extends Activity {
    ImageButton imageButton;
    public void onCreate(Bundle savedInstanceState) {
    public void addListenerOnButton() {
        imageButton = (ImageButton) findViewById(;
        imageButton.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                "ImageButton is clicked!", Toast.LENGTH_SHORT).show();