ImageButton




An ImageButton object represents a clickable Button on the screen with an image instead of text.

Example:

< ImageButton
   android:id="@+id/swimmersImageButton"
   android:onClick = "swimmersImageButtonClick"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_span="3"
   android:src="@drawable/swimmer"
/>

The image files need to be placed in the res/drawable folders.
The image files need to be in all lower case characters.
Notice you do NOT include the file extension (just swimmer in this case).

You can declare a reference to the ImageButton in code.
You only need a reference if you need to refer to the ImageButton.

private ImageButton swimmersImageButton;


You can get a reference to it by calling findViewById
You usually do this in the onCreate method

swimmersImageButton = (ImageButton) findViewById(R.id.swimmersImageButton);



// Click event in Java code
public void swimmersImageButtonClick(View v)
{
   // do whatever
}