当前位置: 移动技术网 > IT编程>移动开发>Android > ImageView点击可变暗的实例代码(android代码技巧)

ImageView点击可变暗的实例代码(android代码技巧)

2019年07月24日  | 移动技术网IT编程  | 我要评论

素描图片,热情仲夏小说,长乐卧佛

废话不多说了,直接给大家贴代码了,具体代码如下所示:

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代码技巧),希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网