The app I\'m currently working on uses a lot of ImageViews as buttons. The graphics on these buttons use the alpha channel to fade out the edges of the button and make them look
I think this solution is simple enough:
final Drawable drawable = ... ;
final int darkenValue = 0x3C000000;
mButton.setOnTouchListener(new OnTouchListener() {
Rect rect;
boolean hasColorFilter = false;
@Override
public boolean onTouch(final View v, final MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
drawable.setColorFilter(darkenValue, Mode.DARKEN);
hasColorFilter = true;
break;
case MotionEvent.ACTION_MOVE:
if (rect.contains(v.getLeft() + (int) motionEvent.getX(), v.getTop()
+ (int) motionEvent.getY())) {
if (!hasColorFilter)
drawable.setColorFilter(darkenValue, Mode.DARKEN);
hasColorFilter = true;
} else {
drawable.setColorFilter(null);
hasColorFilter = false;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
drawable.setColorFilter(null);
hasColorFilter = false;
break;
}
return false;
}
});