ImageView点击可变暗的实例代码(android代码技巧)
程序员文章站
2023-12-19 17:59:22
废话不多说了,直接给大家贴代码了,具体代码如下所示:
import android.content.context;
import android.graphi...
废话不多说了,直接给大家贴代码了,具体代码如下所示:
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代码技巧),希望对大家有所帮助
上一篇: 北二外属于啥档次的大学?北二外算名校吗?