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); } }
自带图片按下去效果的RadioButton
最新推荐文章于 2021-05-31 16:47:43 发布