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 too have irregular looking buttons and needed the tint. In the end, I just resorted to having a state colorlist as my ImageButton
background. Gives the impression that the button color is changing on press and is very straightforward and less compute intensive. I know that this isn't exactly a tint, but it does give it does give necessary visual feedback to the user in what usually is a fleeting moment.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_pressed="true"
android:drawable="@android:color/darker_gray" />
<item android:drawable="@android:color/transparent" />
</selector>
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;
}