您的位置:首页 > 其它

自带图片按下去效果的RadioButton

2016-07-27 13:45 232 查看
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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: