自带图片按下去效果的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); } }
相关文章推荐
- 常用对象类型之间的转换
- YARN 设计理念与基本架构
- Java 8系列之重新认识HashMap
- 基因组组装结果质量评估
- eclipse关闭Updating Error Reporting Database
- Android设计模式-单例模式
- RVO V.S. std::move
- linux下php7安装memcached、redis扩展
- HDU5740 Glorious Brilliance
- POJ-2057 Crossed Ladders (二分,数学)
- 恶心的新浪云sae.sina.com.cn谁买新浪云谁上当
- otsu阈值处理
- 2015CCPC南阳场 C - The Battle of Chibi
- 我的CSDN第一(n)天!
- 链表归并
- 关于textarea使用技巧
- 学习笔记:ASP.NET MVC ModelState验证模型状态
- 如何快速的下载openstack的所有源代码
- 数组与指针
- 8天学通MongoDB——第八天 驱动实践