public void setAlphaWhenTouched(final View touchedView) {
touchedView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
v.setAlpha(0.3f);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
v.setAlpha(1f);
break;
default:
break;
}
return false;
}
});
}