Android Using ImageButton

Most of the time in the application we want to say more about, what button will function on click. But its not possible to write entire statement/description as label of button. And there is option for it to set image/picture as Icon on the button.

In the given below xml you can see, how we can set Image on Button and ImageButton.

And the result will look something like below.

Android Using ImageButton

The ImageButton allows you to display image but not text as a label.

If you want use Image/Picture/Icon with the text label, you have to use Button, which allows you to set Image as well as text also. To set Image along with text use attribute android:drawableTop, android:drawableLeft, android:drawableRight and android:drawableBottom. With the respective order this all attributes allows you to display image at the top, left, right and bottom.

Event you can use all these attributes combinations. Like below.

There another way to set Image on Button, which is setting image on button programmatically.

Look at the Button view set in xml below.

Now set Image and Text programmatically.

The output will look like below.

Android Using ImageButton

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *