It is little bit confusing between ImageView and ImageButton. I think both have mostly same XML attributes. Does any effect to the app if i use ImageView instead of ImageButton?
Asked
Active
Viewed 517 times
-2
-
ImageButton has a non-null background by default. Except this, there's no difference. – Oct 23 '17 at 06:56
-
if there is no difference between them, why both are separated?#peter haddad – md_Danish Oct 23 '17 at 06:57
-
For ImageView you have to add onClick property for clickevent. But ImageButton you dont require it as it provides the property of button. – Chandan kushwaha Oct 23 '17 at 06:58
-
already answered here: https://stackoverflow.com/questions/5847136/difference-between-a-clickable-imageview-and-imagebutton – Prashanthv Oct 23 '17 at 06:58
-
as I said, ImageButton has a non-null background and ImageView doesn't. If you use an ImageButton you might see a button like feel in the background where ImageView has just an image. – Oct 23 '17 at 06:59
-
1. button - 3d rendering of a button that has text. Very simple easy to use. 2. ImageButton - 3d rendeirng of a button but instead of text you are using an image. 3. ImageView - a flat image – Ashutosh Tripathi Oct 23 '17 at 07:27
2 Answers
1
Only the default style is the difference among ImageButton & ImageView. ImageButton has a non-null background by default. Default properties of ImageButton:
- ImageButton.onSetAlpha() method always returns false.
- It's scaleType is set to center, and
- It's always inflated as focusable.

Ashish John
- 1,867
- 2
- 23
- 38
0
Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button, with the standard button background that changes color during different button states. The image on the surface of the button is defined either by the android:src attribute in the XML element or by the setImageResource(int) method.
Src ImageButton
ImageButton is inheriting from ImageView. By default, Image button will be having imageButtonStyle as style. Have a look on source code of ImageButton
public class ImageButton extends ImageView {
public ImageButton(Context context) {
this(context, null);
}
public ImageButton(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.imageButtonStyle);
}
public ImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public ImageButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
setFocusable(true);
}
@Override
protected boolean onSetAlpha(int alpha) {
return false;
}
@Override
public CharSequence getAccessibilityClassName() {
return ImageButton.class.getName();
}
}

Sangeet Suresh
- 2,527
- 1
- 18
- 19