自带图片按下去效果的RadioButton

来源:互联网 发布:注册了淘宝名字能改吗 编辑:程序博客网 时间:2024/04/28 07:31
public class EffectRadioButton extends RadioButton {    public EffectRadioButton(Context context) {        super(context);    }    public EffectRadioButton(Context context, AttributeSet attrs) {        super(context, attrs);    }    public EffectRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    @Override    public boolean onTouchEvent(MotionEvent event) {        this.getParent().requestDisallowInterceptTouchEvent(true);        switch (event.getAction()) {            case MotionEvent.ACTION_DOWN: {                Drawable background = getBackground();                if (background != null)                    background.setColorFilter(0x88000000, android.graphics.PorterDuff.Mode.SRC_ATOP);                Drawable[] drawables = getCompoundDrawables();                Drawable image = drawables[1];                if (image != null)                    image.setColorFilter(0x88000000, android.graphics.PorterDuff.Mode.SRC_ATOP);                invalidate();                break;            }            case MotionEvent.ACTION_CANCEL:            case MotionEvent.ACTION_UP: {                Drawable background = getBackground();                if (background != null)                    background.clearColorFilter();                Drawable[] drawables = getCompoundDrawables();                Drawable image = drawables[1];                if (image != null)                    image.clearColorFilter();                invalidate();                break;            }        }        return super.onTouchEvent(event);    }}
0 0
原创粉丝点击