I using an imageview for button. For normal state it is simple red color image with text on it , in pressed state i want to change the opacity of image.
Now in press state i want to decrease the opacity of this image . To do so the option i know is 1. create an other image with required opacity and use selector to get the effect 2. use color codes for both the states in selector ; But here i already have one image state as image , for the next state i want to decrease the opacity in this image only .
Create a drawable xml resource with bitmap as the root say bg. set android:src="@drawable/background" to the image which you want as the background. set android:alpha="0.4" to any value between 0 to 1 as per the required opacity.
button.setOnTouchListener(this);
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v == button) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
v.setAlpha(0.5f);
} else {
v.setAlpha(1f);
}
}
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With