Last Updated:

Example of using imageButton in Android

ImageButton is a component for building the user interface in Android. It is a button with an image. The widget is represented in Android by the class with which we practice today.ImageButtonandroid.widget.ImageButton

Example of using imageButton in Android

The component has all the properties of a regular button, but has the ability to use an image instead of text.ImageButton

This is done in the same way as in the ImageView widget using the . Let's look at an example of widget markup in a layoutandroid:src

Initializing a widget in code is also simple:

Android provides several methods to work with:ImageButton

  1. The method is used when setting an image by its id (for example, in the code above)setImageResource()
  2. The method is used if you already have a Bitmap instance that you want to install on the .setImageBitmap()ImageButton
  3. The method for setting the instance image is .setImageDrawable()Drawable
  4. A method to set an image by the known .setImageURI()Uri

Installing a listener and clicking on the ImageButton widget occurs in the same way as in a Button.