素描图片,热情仲夏小说,长乐卧佛
废话不多说了,直接给大家贴代码了,具体代码如下所示:
import android.content.context; import android.graphics.colormatrixcolorfilter; import android.util.attributeset; import android.view.motionevent; import android.view.view; import android.widget.imageview; public class myimageview extends imageview{ public myimageview(context context, attributeset attrs) { super(context, attrs); // todo auto-generated constructor stub this.setontouchlistener(view_touch_dark); } public static final ontouchlistener view_touch_dark = new ontouchlistener() { //变暗(三个-50,值越大则效果越深) public final float[] bt_selected_dark = new float[] { 1, 0, 0, 0, -50, 0, 1, 0, 0, -50, 0, 0, 1, 0, -50, 0, 0, 0, 1, 0 }; /* //变亮 public final float[] bt_selected_light = new float[] { 1, 0, 0, 0, 50, 0, 1, 0, 0, 50, 0, 0, 1, 0, 50, 0, 0, 0, 1, 0 }; //恢复 public final float[] bt_not_selected = new float[] { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 }; */ @override public boolean ontouch(view v, motionevent event) { if (event.getaction() == motionevent.action_down) { imageview iv = (imageview) v; iv.setcolorfilter(new colormatrixcolorfilter(bt_selected_dark)); } else if (event.getaction() == motionevent.action_up) { imageview iv = (imageview) v; iv.clearcolorfilter(); } return false; //如为false,执行action_down后不再往下执行 } }; }
以上所述是小编给大家介绍的imageview点击可变暗的实例代码(android代码技巧),希望对大家有所帮助
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android studio开发小型对话机器人app(实例代码)
Android通过Java sdk的方式接入OpenCv的方法
Android 通过cmake的方式接入opencv的方法步骤
Android Studio finish()方法的使用与解决app点击“返回”(直接退出)
Android 进度条 ProgressBar的实现代码(隐藏、出现、加载进度)
网友评论