North Border Software

Home Tutorials Hints & Tips About

Android Apps and Training

Share on Facebook Share on Twitter

Getting Started in Android Development

Part 17 - The Image Button

The next three tutorials look at how we can construct a springboard menu using image buttons and the GridLayout. The focus of this tutorial is how to use the image buttons.

The use of images is a fundamental part of any app. An app that is graphically appealing will be far more successful than one based on non-graphical views alone.

As the name implies, an image button is a view that has the function of a standard button, but uses an image as the background. Like the standard button, you can assign an “onClick” Listener to the button in which you place the code with the button action.

The application of the code in the XML layout is similar to any other view. For this tutorial, four images buttons are placed in a linear layout. The images used can be downloaded here.

Download Download example image buttons

The code defining a typical image button is shown below:

android:background="@drawable/image1" />

The android:background=”@drawable/<image_file>” attribute points to the image in the drawable folder. Remember that you will need an image for each screen density in the respective drawable folder. That is all there is to the image button XML code.

After this tutorial the activity_gridlayout.xml layout should look similar to the one below:

Turning our attention to the java code, there is really nothing new compared to what we have undertaken in the previous tutorials. An onClick listener is setup for each button and the toast is generated for each button. At the end of this tutorial your file should look similar to the one below:

After this tutorial your Android Manifest file should look similar to the one below:

After this tutorial your file should look similar to the one below:

Download Download tutorial set 1

© 2015 North Border Software All rights reserved
Privacy and Cookies Terms of Use Disclaimer Copyright
North Border Software Logo