76

Is there any difference between Button with image, ImageButton and clickable ImageView?

5 Answers 5

94

This probably only covers part of the differences, it would be helpful to actually look at the Android Source tree to see exactly what's going on.

ImageButtons has push states, where as a clickable image does not. You also can't call setText for ImageButton, you can with a regular button.

They all derive from view, but looking at the following extends chain may help a little.

java.lang.Object
↳ android.view.View
   ↳ android.widget.ImageView
       ↳ android.widget.ImageButton

versus

java.lang.Object
↳ android.view.View
   ↳ android.widget.TextView
       ↳ android.widget.Button
Sign up to request clarification or add additional context in comments.

4 Comments

Funny. Another example of problems caused by lack of (a sort of) multiple inheritance.
When to use one versus the other?
What exactly is a push state?
@ShikharMainalee the state of the button when it's being pressed/clicked. Also referred to as the compressed or down state.
19

The differences can be subtle. The most direct way to understanding this is to start with looking at the docs. If you look at the docs for Button you can see that Button is derived from TextView. ImageButton on the other hand is derived from ImageView. So fundamentally, a Button can have text and is clickable, whereas an ImageButton is a bit more flexible in how you set the image. It has methods from its ImageView base class like setImageURI which a Button does not. One of the differences between these two and just a plain ImageView is that you can have button states which is explained in both of the Button and ImageButton docs.

Comments

9
ImageView = Display Images (android:src)

ImageButton = Diaplay Images as imageView and get click effect as button (android:src) and cannot set text to it.

Button = set text and (android:background)

1 Comment

Thank you this is syntax difference of setting. I needed to know actuall differences (when to use or the different look)
4

One other aspect not mentioned in the previous answers is the usage within (for instance) a list item view. If you an embed a Button or ImageButton, the rest of the list item will not receive touch events. But if you use ImageView, it will.

2 Comments

Do you have a source for this? I just ran into this issue with ImageButton, but not with Button with image background
I'm afraid I no longer have access to the source in question. But it was pretty straight-forward - the button forms ate the touch event and the image view did not. I'm sure there are other ways to pass the event upstream, but this was a simple fix that required no refactoring.
0
button instanceof ImageButton == false;
imageButton instanceof Button == false;
button instanceof TextView == true;
imageButton instanceof ImageView == true;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.