Created
January 22, 2014 08:03
-
-
Save was0107/8555088 to your computer and use it in GitHub Desktop.
点击图片变暗或者变亮 ----一张图片实现
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final OnTouchListener TouchLight = new OnTouchListener() { | |
public final float[] BT_SELECTED = 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) { | |
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED)); | |
v.setBackgroundDrawable(v.getBackground()); | |
} else if (event.getAction() == MotionEvent.ACTION_UP) { | |
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED)); | |
v.setBackgroundDrawable(v.getBackground()); | |
} | |
return false; | |
} | |
}; | |
public static final OnTouchListener TouchDark = new OnTouchListener() { | |
public final float[] BT_SELECTED = 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) { | |
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED)); | |
v.setBackgroundDrawable(v.getBackground()); | |
} else if (event.getAction() == MotionEvent.ACTION_UP) { | |
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED)); | |
v.setBackgroundDrawable(v.getBackground()); | |
} | |
return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment