Android ImageButton Control

Android ImageButton Control

Android ImageButton is a button with an image, which a user clicks. A button with an image on the surface and an AbsoluteLayout is what it is know for.


Use ImageButton to give a new view to the button. For example, share button, start button, turn off button, play button, pause button, etc.


Here’s a simple example showing the working on Android iMAGEButton on Android Studio. Here, we will be showing a message on ImageButton click.

If you’re beginning with Android, then learn how to run your first Android app in Android Studio.

Let’s start with the usage of Android ImageButton control.

The src\main\java\com\studyopedia\studyopediaapplication\ is a java class which sets the views. Here we will set the View to be displayed with the setContentView.

On button click, a toast will appear with a message “Studyopedia is a free learning website!” .Toast in Android is a notification message visible in the form of popup. We did the same while working with Android Button Control, but here we will be adding an ImageButton.

ImageButton adds an image to surface of a button.


For src\main\res\layout\activity_main.xml,
We’ll add our UI content here, 1 TextView and 1 ImageButton. Since, we have an ImageButton, so we will be adding an image in the src\main\res\drawable directory.

Here, we added our image submit.png to drawable,

We will get this image in our code using the following attribute,

Now, we will add our code in activity_main.xml,


The content of \src\main\AndroidManifest.xml, provides key information of your app to the system. The system needs this to run your code,


Here’s the code for res/values/strings.xml. The app name and any hardcoded strings will be visible. We hardcoded string “Studyopedia ImageButton Demo App” and used @string/title in activity_main.xml. Here, it gets mentioned under <resources>,


We created an AVD, so now we will run our app using the same AVD. Go to Run > Run app or press the run button or Shift + F10.

This will install your app on the AVD and the following emulator with your app opens up,

Click the ImageButton and now the toast message is visible,


Android Button Control
Android ToggleButton Control
Studyopedia Editorial Staff
Studyopedia Editorial Staff

We work to create free tutorials for all.

No Comments

Post A Comment