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
Your answer was also excellent ;)
I am modifying little bit, it will give you result like this:
Rect rect;
Drawable background;
boolean hasTouchEventCompleted = false;
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
rect = new Rect(v.getLeft(), v.getTop(), v.getRight(),
v.getBottom());
hasTouchEventCompleted = false;
background = v.getBackground();
background.setColorFilter(0x99c7c7c7,
android.graphics.PorterDuff.Mode.MULTIPLY);
v.setBackgroundDrawable(background);
} else if (event.getAction() == MotionEvent.ACTION_UP
&& !hasTouchEventCompleted) {
background.setColorFilter(null);
v.setBackgroundDrawable(background);
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (!rect.contains(v.getLeft() + (int) event.getX(), v.getTop()
+ (int) event.getY())) {
// User moved outside bounds
background.setColorFilter(null);
v.setBackgroundDrawable(background);
hasTouchEventCompleted = true;
}
}
//Must return false, otherwise you need to handle Click events yourself.
return false;
}