Difference between a clickable ImageView and ImageButton

前端 未结 3 1145

I\'m just wondering if there is any significant difference between an ImageView that\'s set to be clickable, compared with an ImageButton?

<
3条回答
  •  一向
    一向 (楼主)
    2020-11-29 20:27

    ImageButton is inherited from ImageView

    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 defStyle) {
        super(context, attrs, defStyle);
        setFocusable(true);
    }
    
    @Override
    protected boolean onSetAlpha(int alpha) {
        return false;
    }
    
    @Override
    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
        super.onInitializeAccessibilityEvent(event);
        event.setClassName(ImageButton.class.getName());
    }
    
    @Override
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
        super.onInitializeAccessibilityNodeInfo(info);
        info.setClassName(ImageButton.class.getName());
    }
    

    as @Micheal describe i just add details to his answer

提交回复
热议问题